Skip to content

naqvijafar91/go-workshops

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang Workshop

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.

What will be covered?

  1. Introduction
  2. Variables and Constants
  3. Functions
  4. Packages
  5. Conditional Statements
  6. Loops
  7. Arrays
  8. Slice
  9. Variadic Functions
  10. Maps
  11. Strings
  12. Pointers
  13. Structs
  14. Interface
  15. Goroutines, channels
  16. sync.WaitGroup and sync.Mutex
  17. Unit Testing
  18. Object Oriented Programming in Go
  19. WATS

About Go

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:

Go language characteristics

  • statically compiled (one fat binary with all dependencies)

  • Garbage Collected

  • Strong types

  • Functions as first class citizens

  • Object Oriented (but without inheritance and classes)

Why it's worth of your time?

  • easy deployment (no dependencies, single binary statically linked)

  • no more code style wars - gofmt

  • integrated package downloader go get

  • integrated code validation go vet and golint (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 ...

Workshop prerequisites

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.

Golang installation

For recent installation instructions please refer to Golang installation guide

You'll need git to be installed

Docker install

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.

Docker Compose Installation

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

Init workshops to play on your machine with code

"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 Tools

Included

IDEs

Github style - project structure

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.

Packages and Importing

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"

Getting and installing external packages

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

Package managers

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

Releases

No releases published

Packages

No packages published