Go Lang

Go Lang

Learning

install package

  • go get

Update your PATH environment variable

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}
}

reference

Private and Public Visibility

  • private Lowwer case -> func a()
  • public Upper case => func A()

array, slice

  • array -> fix list
  • slice -> not fix

Receiver method

Link