Help us understand the problem. What is going on with this article?

GO言語をMacで使ってみる インストール

More than 1 year has passed since last update.

 環境

  • macOS
  • Homebrew

事前準備

Homebrewをインストールしておく

手順

インストール

$ brew install go
==> Downloading https://homebrew.bintray.com/bottles/go-1.9.4.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring go-1.9.4.high_sierra.bottle.tar.gz
==> Caveats
A valid GOPATH is required to use the `go get` command.
If $GOPATH is not specified, $HOME/go will be used by default:
  https://golang.org/doc/code.html#GOPATH

You may wish to add the GOROOT-based install location to your PATH:
  export PATH=$PATH:/usr/local/opt/go/libexec/bin
==> Summary
🍺  /usr/local/Cellar/go/1.9.4: 7,654 files, 294MB

バージョンの確認

$ go version
go version go1.9.4 darwin/amd64

Hello World!

hello.go
package main
import "fmt"

func main() {
    fmt.Printf("Hello World!\n")
}

実行

$ go run hello.go
Hello World!

ビルド

$ go build hello.go
$ ls
hello       hello.go
$ ./hello
Hello World!

覚書

癖で↓みたいに書いたら「syntax error」になった

hello.go
func main()
{
    fmt.Printf("Hello World!\n")
}

「syntax error」の件もあったのでgoのコーディング規約を検索

最初の方を少し読んだだけだけどインデントはハードタブらしい

gofmtコマンドで修正してくれるらしい

$ gofmt hello.go
package main

import "fmt"

func main() {
    fmt.Printf("Hello World!\n")
}

packageとimportの間に1行追加されてインデントがtabになりました

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした