go¶
Installation¶
$ brew install go
et ajouter le chemin de l'installation au $PATH
export PATH=$PATH:/usr/local/opt/go/libexec/bin
Créer un workspace:¶
Par défaut: $HOME/go
Sinon:
$ mkdir $HOME/Documents/go
puis créer 2 sous-dossiers:
# programmes
$ mkdir $HOME/Documents/go/bin
# sources
$ mkdir $HOME/Documents/go/src
Ajouter les 2 variables d'environnement à .bash_profile
export GOPATH=$HOME/Documents/go
export GOBIN=$HOME/Documents/go/bin
Ajouter les dossiers des exécutables au $PATH
export PATH=$PATH:$(go env GOPATH)/bin
$ go env
GOARCH="amd64"
GOBIN="/Users/xxx/Documents/go/bin"
GOCACHE="/Users/xxx/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/xxx/Documents/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10.3/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/s5/zy63nf3953sb_4k0ppcy16sw0000gn/T/go-build083426751=/tmp/go-build -gno-record-gcc-switches -fno-common"
Installer une application:¶
GO111MODULE=on go install github.com/olivere/iterm2-imagetools/cmd/imgcat@latest
GO111MODULE=on go install github.com/olivere/iterm2-imagetools/cmd/imgls@latest
Créer une application:¶
Dans le dossier src, créer un nouveau dossier pour l'application hello:
$ mkdir $GOPATH/src/hello
$ cd $GOPATH/src/hello
Créer un fichier hello.go pour l'application
$ cat hello.go
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
Le compiler:
$ go build
# crée un executable 'hello'
L'installer:
$ go install
# déplacer l'exécutable dans le dossier bin
ou la supprimer
$ go clean -i
Dernière mise à jour:
March 4, 2022