Go Lang
Go Lang
Learning
install package
- go get
Update your PATH environment variable
- export GOPATH=$HOME/go
- export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
- link: https://medium.com/@richardeng/in-the-beginning-61c7e63a3ea6
Go routine
- icsendonly := make (<-chan int) //a channel that can only send data - arrow going out is sending
- icrecvonly := make (chan<- int) //a channel that can only receive a data - arrow going in is receiving
Pointer
- ส่ง &
- รับ *
package main
import "fmt"
type human struct {
name string
age int
isAdult bool
}
// ใช้ * แทนการ dereference หรือการถอดเอาค่าที่แท้จริงออกมา
func setAdult(h *human) {
h.isAdult = h.age >= 18
}
func main() {
somchai := human{name: "Somchai", age: 23}
// ใช้ & แทนการอ้างถึง reference
setAdult(&somchai)
fmt.Println(somchai) // {Somchai 23 true}
}
Private and Public Visibility
- private Lowwer case -> func a()
- public Upper case => func A()
array, slice
- array -> fix list
- slice -> not fix