Go: Difference between revisions

From Leo's Notes
This page was last edited on 10 August 2017, at 03:38.
m layout
No edit summary
Line 1: Line 1:


== Introduction ==
== Introduction ==
=== Installation ===
The simplest way to get the latest version of go is to download it from https://golang.org/dl/. Extract the package to {{code|/usr/local/go}} and then set the following environment variables:
{{highlight|lang=terminal|code=
$ export PATH=$PATH:/usr/local/go/bin
$ export GOPATH=$HOME/go
}}
=== Fetching Packages ===
You can get go packages using the {{code|go get}} command. This will download it to your {{code|$GOPATH/src}} directory. In order to use the package, you will also need to build it by using the {{code|go build}} command.
Eg:
{{highlight|lang=terminal|code=
$ go get github.com/miekg/dns
$ go build github.com/miekg/dns
}}
=== Simple Program ===
Create your program in {{code|$GOPATH/src/}}, ideally under a unique namespace. To build, run {{code|go build}} followed by your namespace and program name. If it compiles properly, the program will be placed in the current working directory.


== Resources ==
== Resources ==

Revision as of 03:38, 10 August 2017

Introduction

Installation

The simplest way to get the latest version of go is to download it from https://golang.org/dl/. Extract the package to /usr/local/go and then set the following environment variables:

$ export PATH=$PATH:/usr/local/go/bin
$ export GOPATH=$HOME/go

Fetching Packages

You can get go packages using the go get command. This will download it to your $GOPATH/src directory. In order to use the package, you will also need to build it by using the go build command.

Eg:

$ go get github.com/miekg/dns
$ go build github.com/miekg/dns

Simple Program

Create your program in $GOPATH/src/, ideally under a unique namespace. To build, run go build followed by your namespace and program name. If it compiles properly, the program will be placed in the current working directory.


Resources

Play with golang online.

Guides

Quick Overview

TBD