142 lines
2.1 KiB
Markdown
142 lines
2.1 KiB
Markdown
# go
|
|
|
|
[The Go Programming Language](https://golang.org/)
|
|
|
|
|
|
|
|
### Installation
|
|
|
|
```bash
|
|
$ brew install go
|
|
```
|
|
|
|
et ajouter le chemin de l'installation au $PATH
|
|
|
|
```bash
|
|
export PATH=$PATH:/usr/local/opt/go/libexec/bin
|
|
```
|
|
|
|
|
|
|
|
### Créer un workspace:
|
|
|
|
Par défaut: $HOME/go
|
|
|
|
Sinon:
|
|
|
|
```bash
|
|
$ mkdir $HOME/Documents/go
|
|
```
|
|
|
|
puis créer 2 sous-dossiers:
|
|
|
|
```bash
|
|
# programmes
|
|
$ mkdir $HOME/Documents/go/bin
|
|
|
|
# sources
|
|
$ mkdir $HOME/Documents/go/src
|
|
|
|
```
|
|
|
|
Ajouter les 2 variables d'environnement à .bash_profile
|
|
|
|
```bash
|
|
export GOPATH=$HOME/Documents/go
|
|
export GOBIN=$HOME/Documents/go/bin
|
|
```
|
|
|
|
Ajouter les dossiers des exécutables au $PATH
|
|
|
|
```bash
|
|
export PATH=$PATH:$(go env GOPATH)/bin
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
$ 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:
|
|
|
|
```bash
|
|
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**:
|
|
|
|
```bash
|
|
$ mkdir $GOPATH/src/hello
|
|
|
|
$ cd $GOPATH/src/hello
|
|
```
|
|
|
|
Créer un fichier **hello.go** pour l'application
|
|
|
|
```bash
|
|
$ cat hello.go
|
|
package main
|
|
|
|
import "fmt"
|
|
|
|
func main() {
|
|
fmt.Printf("hello, world\n")
|
|
}
|
|
|
|
```
|
|
|
|
Le compiler:
|
|
|
|
```bash
|
|
$ go build
|
|
|
|
# crée un executable 'hello'
|
|
```
|
|
|
|
L'installer:
|
|
|
|
```bash
|
|
$ go install
|
|
|
|
# déplacer l'exécutable dans le dossier bin
|
|
```
|
|
|
|
ou la supprimer
|
|
|
|
```bash
|
|
$ go clean -i
|
|
```
|
|
|