This repository contains files needed for managing Go language workshop - it's some kind of quite complete walk-through of Go language. Feel free to look at the code, there are many comments which could be useful for beginners and semi-intermediate Go developers.
- Introduction
- Variables and Constants
- Functions
- Packages
- Conditional Statements
- Loops
- Arrays
- Slice
- Variadic Functions
- Maps
- Strings
- Pointers
- Structs
- Interface
- Goroutines, channels
- sync.WaitGroup and sync.Mutex
- Unit Testing
- Object Oriented Programming in Go
- WATS
Who designed Go language?
-
Rob Pike (Unix, UTF-8)
-
Ken Thompson (Unix author, UTF-8, B lang)
-
Robert Griesemer (V8, Java Hotspot (Oracle Java), GFS)
but those above are only ignitors of whole contributions: https://golang.org/AUTHORS
Why go
was developed by Google? They have a lot of problems in C/Python/Java codebases:
-
speed up development
-
speed up compiling
-
multicore systems
sources:
-
statically compiled (one fat binary with all dependencies)
-
Garbage Collected
-
Strong types
-
Functions as first class citizens
-
Object Oriented (but without inheritance and classes)
-
easy deployment (no dependencies, single binary statically linked)
-
no more code style wars -
gofmt
-
integrated package downloader
go get
-
integrated code validation
go vet
andgolint
(github.com/golang/lint) -
nice playground (https://play.golang.org/)
-
gocode
intellisense server - you don't need fat IDE to write go code, you can use now editor which you love (Sublime, Atom, Vim, Emacs, VSCode) -
very fast compilation - if you're going from JAVA world you'll be really surprised
-
quite complete standard library - template/html, performant www servers, json, xml, streams, io, buffers, first class citizen concurrency
-
easy to use cross-compilation (x64, ARM, 386, Mac, Windows)
-
easy start, bunch of editors, all things simply work
-
http2 in core
-
testing included
-
benchmarking of code included
-
very low entry barrier
-
hype, one of fastest growing language, many new projects are in Go recently
-
concurrency
-
great documentation generator
-
and many many more ...
You can install golang
and docker
using your preferred way i.e. your OS package manager (brew, pacman, apt, snap or other) or you can simply follow installation instruction on go and docker sites.
For recent installation instructions please refer to Golang installation guide
You'll need git
to be installed
Docker is the company driving the container movement and the only container platform provider to address every application across the hybrid cloud. Today’s businesses are under pressure to digitally transform but are constrained by existing applications and infrastructure while rationalizing an increasingly diverse portfolio of clouds, datacenters and application architectures. Docker enables true independence between applications and infrastructure and developers and IT ops to unlock their potential and creates a model for better collaboration and innovation.
For recent docker installation please follow Docker installation guide for your OS.
Docker is needed for some parts of workshops for running databases or other needed dependencies. Also will be needed to complete homework.
Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.
To install docker compose please follow Docker compose installation guide
"go get" command is the standard way of downloading and installing packages and related dependencies. "go get" command clones a git repo to your local machine at $GOPATH/src/github.com/
go get go-workshops
cd \$GOPATH/src/go-workshops
-
go test - included testing framework
-
go fmt - code formater - only one valid coding standard - fmt library website
-
go vet - code validator and fixer - vet library website
-
go oracle - dependencies analyser (can be integrated in editor) oracle web site
-
godoc - great documentation generator and viewer
-
gocode - autocomplete service - gocode library website
-
IntelliJ Go plugin https://plugins.jetbrains.com/plugin/9568-go
-
GoLand - https://www.jetbrains.com/go/
-
Emacs - go-mode
-
Vim - vim-go
-
Visual Studio Code (for the workshop)
-
LiteIDE
-
SublimeText
-
Atom
In go, idiomatic way is to organise code in "github style", so part of the path is looking like server address to library. Of course if you want you don't need to do this, but whole ecosystem works that way.
bin/
hello # command executable
outyet # command executable
src/
[github.com/golang/example/](https://github.com/golang/example/)
.git/ # Git repository metadata
hello/
hello.go # command source
outyet/
main.go # command source
main_test.go # test source
stringutil/
reverse.go # package source
reverse_test.go # test source
[golang.org/x/image/](https://golang.org/x/image/)
.git/ # Git repository metadata
bmp/
reader.go # package source
writer.go # package source
... (many more repositories and packages omitted) ...
Environment variable $GOPATH
is responsible for path to the root dir of src
, bin
and pkg
directories.
package
in go is in form of files with directive package package_name
on top of each file. Package by default is imported as full path to package.
import "go-workshops/010-basics-importing/sub"
To get external package we need to run go install which will get sources and binaries and put them to src
/bin
/pkg
directories
go install external.package.com/uri/to/package
Currently most advanced in go ecosystem is dep
https://github.com/golang/dep
You can init your project:
$ dep init
$ ls
Gopkg.toml Gopkg.lock vendor/
after that dep will add vendor dir where all dependencies will be loaded (In go after 1.5 vendor
dir have preference over "github style $GOPATH
based directories - when compiler will not find library in vendor dir it'll try to take it from $GOPATH
).
For more details please refer to dep
documentation at https://golang.github.io/dep/docs/daily-dep.html