目次
インストール手順
cd `
git clone https://github.com/syndbg/goenv.git `/.goenv
echo 'export GOENV_ROOT="$HOME/.goenv"' >> `/.bash_profile
echo 'export PATH="$GOENV_ROOT/bin:$PATH"' >> `/.bash_profile
- 「goenv init」を呼び出してShimsとオートコンプリートを有効にする。
echo 'eval "$(goenv init -)"' >> `/.bash_profile
source `/.bash_profile
goenv install 1.11.0
go version
`/.bash_profileに
export GOENV_VERSION=1.11.0
アンインストール
export GOENV_ROOT="$HOME/.goenv"
export PATH="$GOENV_ROOT/bin:$PATH"
eval "$(goenv init -)"
rm -rf `goenv root`
実行方法
package main
import "fmt"
function main() {
fmt.Printf("hello, world¥n")
}
go build hello.go
./hello
go run hello.go
データ型
var ival int
var fval float64
var bval bool
var sval string
ival := 10
fval := 12.3
bval := true
sval := "hoge"
var (
ival int
fval float64
bval bool
sval string
)
ival, fval, bval, sval := 10, 10.1, true, "hoge"
文字列処理
var sval string
sval = "good " + "moring"
fmt.Println(sval)
配列
var iVals [5]int
iVals[0] = 10
iVals[1] = 20
iVals[2] = 30
fmt.Println(iVals)
iVals := [...]int{10, 20, 30, 0, 0}
fmt.Println(iVals)
ポインタ型
sVal := "hoge"
var psVal *string
psVal = &sVal
fmt.Println(psVal)
fmt.Println(*psVal)
関数
package main
import "fmt"
func hello(aVal string) string {
return "hello " + aVal
}
func main() {
fmt.Println(hello("taro"))
}
package main
import "fmt"
func hello(aVal string) (string, string) {
return "hello ", aVal
}
func main() {
var sVal1, sVal2 string
sVal1, sVal2 = hello("taro")
fmt.Println(sVal1 + " " + sVal2)
}
package main
import "fmt"
func main() {
var sVal1, sVal2 string
sVal1, sVal2 = func (aVal string) (string, string) {
return "hello ", aVal
} ("taro")
fmt.Println(sVal1 + " " + sVal2)
}
参考サイト
GitHub - syndbg/goenv: Like pyenv and rbenv, but for Go.