※ 08/28/2020 - v1.15
Installation
Official Homepage
https://golang.org/dl
You can download and install Go through this official website.
You can also install Go with package managers.
On MAC
$ brew install go
On Windows
I am using Chocolatey. If you use this, you can install Go like this.
$ choco install -y golang
GOROOT
On Windows
GOROOT is an installation path of Go.
Based on the current version, the Go binary contains this information and does not need to be explicitly specified.
If you change the installation path, you should set an appropriate path to the environment variable $GOROOT.
GOPATH
The environment variable $GOPATH is a workspace to develop with Go, and it must be set.
GOPATH should be different from GOROOT.
GOPATH is composed as below.
GOPATH
+-- bin/
+-- pkg/
+-- src/
This structure should be maintained.
$GOPATH/src/<Repository FQDN>/<Repository Path>
You can change the location of $GOPATH if you want.
On Mac
$GOPATH is usually located in /Users/<username>/go/.
REPL (Read-Eval-Print Loop)
There is no default provided REPL in Go.
If you are familiar with online, you can use this site.
Online Go REPL
https://play.golang.org
Of course there are places available on other commercial sites.
If you are familiar with offline, you need to install 3rd party tool.
$ go get -u github.com/motemem/gore/cmd/gore
Usage
// Start
$ gore
// Finish
<CTRL-d> or :q
Formatter
Go has a built-in formatter. Go supports only one style as its own philosophy, so we can easily achieve code uniformity.
I love this thing !!!
Usage
$ gofmt -w <filename>
Adding -w option can overwrite to the certain files.
Linter
Go has built-in go vet and official tool golint as a linter.
go vet helps to find a potential bug.
golint helps to find a coding style that is not like Go.
golint is not a built-in tool, so you need to install it for using it.
$ go get -u golang.org/x/lint/golint
Usage
$ go vet <file> or <folder>
$ golint <file> or <folder>
Task Runner
Go uses Makefile as a task runner.
env Command
env command is used when check the environment variables of Go.
Usage
$ go env
$ go env GOROOT
$ go env GOPATH
'Go' 카테고리의 다른 글
[Go] Configure VSCode (0) | 2020.11.28 |
---|---|
[Go] User-Defined Type (0) | 2020.11.02 |
[Go] Basic (0) | 2020.10.26 |
[Go] Variable (0) | 2020.10.21 |
[Go] Data Types (0) | 2020.10.21 |
댓글