golang notes(2)

1, IDE (goland)

One may need 'jetbrains-agent-latest.zip': 

鏈接: https://pan.baidu.com/s/1Ze1TUhByRNX7BkAU8mNpIw 提取碼: dx2k

 

2, defer

<Defer, Panic, and Recover> is an excellent doc:  https://www.cnblogs.com/kaid/p/9698477.html

 

3, Execise: Slices

package main

import (
	"fmt"
	"golang.org/x/tour/pic"
)

func Pic(dx, dy int) [][]uint8 {
	var p [][]uint8 = make([][]uint8, dx)

	for i := 0; i < dx; i++ {
		p[i] = make([]uint8, dy)
		for j :=0; j < dy; j++ {
			p[i][j] = uint8(i*j)
		}
	}

	return p
}

func main() {
    //fmt.Println(Pic(16, 16))
    pic.Show(Pic)
}

The result output looks like:

IMAGE:iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAIAAADTED8xAACAAElEQVR42uy9B3jUVfb/P7r21dVVdy1r74o1o
//omitted
348mQMB8NVXuvpRP57MgQD4+mtd/agfT+ZAAPz1r7r6UT+ezIEA+OYbXf2oH0/mQAD87W+6+lE/nsyBAPj2W139qB9P5kAAfPedrn7UjydzIADu3dPVj/rxZI7/HwAA//9vd4RSMvSyIgAAAABJRU5ErkJggg==

From here(https://stackoverflow.com/questions/18553246/tour-golang-org36-the-functionality-implemented-by-pic-show), we can see the implementation of pic.Show:

Funny thing is it ends up printing the string "IMAGE:" followed by the base64 encoded string. Seems that play.golang.org parses the output converting this to an img tag. Try the following example: http://play.golang.org/p/RZPqp164eS 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章