Entries from 2016-07-28 to 1 day

Go unit test サンプル

Go

Goでunit testを実行する場合の簡単なサンプルを作成してみる。 github.com dog.go package model type Dog struct { Name string Age int8 } func NewDog(name string, age int8) *Dog { return &Dog{Name: name, Age:age} } dog_test.go package model imp…

Go Channels サンプル

Go

The Go Playground package main import "fmt" func main() { messages1 := make(chan string) messages2 := make(chan string) messages3 := make(chan string) go func() { messages1 <- "ping1" }() go func() { messages2 <- "ping2" }() go func() { me…

Goroutine サンプル

Go

Goroutineのサンプルを作ってみる。 まずは、簡単なところから、 github.com The Go Playground package main import "fmt" func f(from string) { for i := 0; i < 3; i++ { fmt.Println(from, ":", i) } } func main() { f("direct") go f("goroutine1") g…