More Related Content Similar to インフラ運用管理ツールとGolang OSS運用管理勉強会LT (20) More from Daisuke Ikeda (15) インフラ運用管理ツールとGolang OSS運用管理勉強会LT8. Easy build
$ go build sample.go
$ ls -lh
-rwxr-xr-x 1 ike_dai staff 2.2M 4 19 23:35 sample
-rw-r--r-- 1 ike_dai staff 77B 4 19 23:35 sample.go
$ ./sample
Hello World
$ go run sample.go
package main
import "fmt"
func main() {
fmt.Println("Hello World")
}
※都度buildしなくてもgo runで即時実行可
10. Cross Compile
$ GOOS=linux GOARCH=amd64 go build sample.go
Linux
Windows
MacOS
$ GOOS=windows GOARCH=amd64 go build sample.go
$ GOOS=darwin GOARCH=amd64 go build sample.go
20. Go routine & channel
関数にgoつけて実行するだけで非同期並列処理化
並列処理間のデータ連携にはchannelで送受信
package main
import "fmt"
func main() {
fmt.Println("Hello World")
ch := make(chan int)
go backend_process(ch)
receive := <-ch
fmt.Println(receive)
}
func backend_process(ch chan int) {
fmt.Println("Backend Process")
ch <- 1
}
$ go run sample.go
Hello World
Backend Process
1
21. Go routine & channel
関数にgoつけて実行するだけで非同期並列処理化
並列処理間のデータ連携にはchannelで送受信
package main
import "fmt"
func main() {
fmt.Println("Hello World")
ch := make(chan int)
go backend_process(ch)
receive := <-ch
fmt.Println(receive)
}
func backend_process(ch chan int) {
fmt.Println("Backend Process")
ch <- 1
}
$ go run sample.go
Hello World
Backend Process
1
複数処理を並行で
バックエンド処理させるのが簡単