今更感ですが、Go言語を習得しようと思い立ったので、自学習にアウトプットしていおきます。
ちなみに、開発環境は「Mac」です。
Go言語とは
3行で説明すると
- 2009年Googleが作ったプログラム言語
- 親はC言語、静的型付けのコンパイル言語
- フリーかつオープンソース
対応OS
- Linux / FreeBSD
- Mac OS X
- Windows
※2020/01時点
Go言語のインストール
インストール
brew install go
インストールした場所の確認
which go
インストールしたバージョンの確認
go version
Hello worldを表示するプログラムの実装
ファイルを作成
touch hello_world.go
ファイルを編集
vim hello_world.go
package main
import "fmt"
func main() {
fmt.Printf("Hello World\n")
}
fmtパッケージは、フォーマットI/Oを実装しており、C言語のprintfおよびscanfと似た関数を持ちます。フォーマットの「書式」はC言語から派生していますが、より単純化されています。
プログラムをビルドする
go build hello_world.go
直接プログラムファイルを実行
go run hello_world.go
コンパイルしたファイルを実行
hello_world