Building Blockchain with Go 👣
rest.go
- url 정의
- router 만들기 (handler)
- controller 만들기
In Go, nil
is the zero value for pointers, interfaces, maps, slices, channels and function types, representing an uninitialized value.
함수명을 대문자로 시작하면 외부에서 호출 가능
- Golang functions vs methods
- Member variable : 대소문자 구분
- Once : 스레드, 고루틴과 상관 없이 오지 1번만 실행
- Singleton Pattern : 단 하나의 instance만을 공유
- text/template
- Marshal : interface를 받아 JSON으로 변환
- Struct field tags
- Stringer
- MarshalText
- Gorilla Web Toolkit
- bolt db
- gob : value를 byte로 encode or decode
- iota : iota를 활용한 프로그래밍
- godoc
godoc -http=:6060
// Only Send Channel
func send(c chan<- int) {
for i := range [10]int{} {
fmt.Printf(">> sending %d <<\n", i)
c <- i
fmt.Printf(">> sent %d <<\n", i)
}
close(c) // avoid deadlock
}
// Only Receive Channel
func receive(c <-chan int) {
for {
time.Sleep(10 * time.Second)
a, ok := <-c
if !ok {
fmt.Println("Done")
break
}
fmt.Printf("|| received %d ||\n", a)
}
}
func main() {
c := make(chan int, 10) // Buffer Channel
go send(c)
receive(c)
}
go test ./... -v
Coverage
# create profile
go test -v -coverprofile cover.out ./...
# visualize
go tool cover -html=cover.out