Golang

naming convention

Names are as important in Go as in any other language. They even have semantic effect: the visibility of a name outside a package is determined by whether its first character is upper case. It’s therefore worth spending a little time talking about naming conventions in Go programs.

install golang local package

go install github.com/user/hello
go clean -i github.com/user/hello

channel operation

code describe
channel <- value Blocking send
<-channel Receive and discard
x := <-channel Receive and store
x, ok := <-channel As above & check for channel closed & empty

Golang ternary operation

SO link

c := map[bool]int{true: 1, false: 0} [5 > 4]

Golang reference type VS value type

reference type:slice,map,channel value type: array

Golang types

map

struct {
	m *internalHashtable
}

channel

struct {
	c *internalChannel
}

slice

struct {
	array *internalArray
	len   int
	cap   int
}

Generate 2-D array

  1. Using array
c := [5][5]int{}
fmt.Println(c)
  1. Using slice
a := make([][]int, dy)
for i := range a {
    a[i] = make([]int, dx)
}
fmt.Println(a)

Website About Golang

Golang Implementation

Golang crawler