margo

module
v0.0.0-...-3215db2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2022 License: BSD-3-Clause

README

margo

margo (the Marvelous Go tutorial) is a simple repository holding sources for an introduction to Go.

The slides are here:

Bootstrapping the work environment

Installing the Go toolchain

The Go hands-on session obviously needs a working Go toolchain.

There are 3 ways to achieve this:

  • install Go via your favorite package manager (yum, apt-get, fink, ...)
  • install Go via docker
  • install Go manually.

Installing and configuring Go can be achieved by following the instructions of the official Go installation page: https://golang.org/doc/install

Setting up the work environment

Like python and its $PYTHONPATH environment variable, Go uses $GOPATH to locate packages' source trees. You can choose whatever you like (obviously a directory under which you have read/write access, though.)

In the following, we'll assume you chose $HOME/go:

$ mkdir -p $HOME/go
$ export GOPATH=$HOME/go
$ export PATH=$GOPATH/bin:$PATH

Make sure the go tool is correctly setup:

$ go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="$HOME/go"
GORACE=""
GOROOT="/usr/lib/golang"
GOTOOLDIR="$HOME/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

(on other platforms/architectures, the output might differ slightly. The important env.vars. are GOPATH and GOROOT.)

Testing go

Now that the go tool is correctly setup, let's try to fetch some code. For this part, you'll need the following tools installed to actually retrieve the code from the repositories:

  • git

Without further ado:

$ go install -v github.com/sbinet/margo/cmd/margo-hello@latest
go: downloading github.com/sbinet/margo v0.0.0-20200115082936-ccffedad4555
github.com/sbinet/margo/cmd/margo-hello

go install downloaded (cloned, in git speak) the whole github.com/sbinet/margo repository (under $GOPATH/pkg/mod) and compiled the margo-hello command. As the compilation was successful, it also installed the margo-hello command under $GOPATH/bin.

The margo-hello command is now available from your shell:

$ margo-hello
Hello MarGo!

$ margo-hello you
Hello you!

Setting up your favorite editor

Extensive documentation on how to setup your editor (for code highlighting, code completion, ...) is available here:

https://github.com/golang/go/wiki/IDEsAndTextEditorPlugins

At the very least, you should try to install and setup goimports as explained here:

https://godoc.org/golang.org/x/tools/cmd/goimports

goimports provides automatic code formating as well as automated insertion/deletion of used/unused packages (in your import package statements.)

Documentation

The Go programming language is quite new (released in 2009) but ships already with quite a fair amount of documentation. Here are a few pointers:

For more advanced topics:

Directories

Path Synopsis
cmd
indexer command
margo-hello command
margo-hello is a simple Hello World command to test everything is correctly setup
margo-hello is a simple Hello World command to test everything is correctly setup
daq
Package daq contains types and functions to build a simple DAQ system.
Package daq contains types and functions to build a simple DAQ system.
cmd/daq-cli command
cmd/daq-mon command
cmd/daq-srv command
part-2
_code command
part-3
_code command
part-4
_code command
rest command
part-5
_code command
part-6
whispernet/skeleton/part1 command
This program reads from standard input and writes JSON-encoded messages to standard output.
This program reads from standard input and writes JSON-encoded messages to standard output.
whispernet/skeleton/part10 command
This program extends part 9.
This program extends part 9.
whispernet/skeleton/part2 command
This program extends part 1.
This program extends part 1.
whispernet/skeleton/part3 command
This program listens on the host and port specified by the -listen flag.
This program listens on the host and port specified by the -listen flag.
whispernet/skeleton/part4 command
This program is a combination of parts 2 and 3.
This program is a combination of parts 2 and 3.
whispernet/skeleton/part5 command
This program extends part 4.
This program extends part 4.
whispernet/skeleton/part6 command
This program is functionally equivalent to part 5, but the reading from standard input and writing to the network connection are done by separate goroutines.
This program is functionally equivalent to part 5, but the reading from standard input and writing to the network connection are done by separate goroutines.
whispernet/skeleton/part7 command
This program extends part 6 by adding a Peers type.
This program extends part 6 by adding a Peers type.
whispernet/skeleton/part8 command
This program extends part 7.
This program extends part 7.
whispernet/skeleton/part9 command
This program extends part 8.
This program extends part 8.
whispernet/solution/part01 command
This program reads from standard input and writes JSON-encoded messages to standard output.
This program reads from standard input and writes JSON-encoded messages to standard output.
whispernet/solution/part02 command
This program extends part 1.
This program extends part 1.
whispernet/solution/part03 command
This program listens on the host and port specified by the -listen flag.
This program listens on the host and port specified by the -listen flag.
whispernet/solution/part04 command
This program is a combination of parts 2 and 3.
This program is a combination of parts 2 and 3.
whispernet/solution/part05 command
This program extends part 4.
This program extends part 4.
whispernet/solution/part06 command
This program is functionally equivalent to part 5, but the reading from standard input and writing to the network connection are done by separate goroutines.
This program is functionally equivalent to part 5, but the reading from standard input and writing to the network connection are done by separate goroutines.
whispernet/solution/part07 command
This program extends part 6 by adding a Peers type.
This program extends part 6 by adding a Peers type.
whispernet/solution/part08 command
This program extends part 7.
This program extends part 7.
whispernet/solution/part09 command
This program extends part 8.
This program extends part 8.
whispernet/solution/part10 command
This program extends part 9.
This program extends part 9.
part-8
_code command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL