Learn Go by project: Souin

Sylvain Combraque

Creator of Souin cache system

Træfik helper

Open-source contributor

@Darkweak

@Darkweak_dev

Let's

Golang history

Developed by Google

Started on 2003

Opensourced on 2009

Keith Clark et Francis McCabe

Written in C

Advantages

One binary file output

Build cross-platform

Easy learning curve

Not tricky language

Multithreading

Concurrency

Written in Golang

For the web

My history with Golang

Traefik

Emile Vauge

Written in GO

Easy to use

French Quality

Where is the cache ?

github.com/Darkweak/Souin

Golang is normalized

$GOPATH

/bin
/pkg
/src

/bin Contains fully compiled Go softwares based on pkg objects
/pkg contains Go package objects compiled from src directory Go source code packages
/src Contains readable development sources including dependencies

$GOROOT

Golang SDK

$GOOS

  • aix
  • android
  • darwin
  • dragonfly
  • freebsd
  • hurd
  • illumos
  • js
  • linux
  • netbsd
  • openbsd
  • plan9
  • solaris
  • windows
  • zos

$GOARCH

  • 386
  • amd64
  • arm
  • armbe
  • arm64
  • arm64be
  • ppc64
  • ppc64le
  • mips
  • mipsle
  • mips64
  • mips64le
  • mips64p32
  • mips64p32le
  • ppc

  • riscv
  • riscv64
  • s390
  • s390x
  • sparc
  • sparc64
  • wasm

Live demo

https://github.com/Darkweak/golang-starter

First Hello World

Typing and variables

Functions and returns

Goroutines

A goroutine is a lightweight thread of execution.

Go will run both at same time, then your main thread will continue the main script in parallel without taking care of second thread

Channels

Testing

More explicit example ?

Usefull tools

Usefull tools

Testing

Linter

  • golint
  • govet
  • go test
  • go tool

Usefull tools

Testing

Linter

  • golint
  • go vet
  • go test
  • go tool

Usefull tools

Testing

Linter

  • golint
  • govet
  • go test
  • go tool
// Run all tests
go test -v ./...

// Run all tests and generate a cover
// reporting
go test ./... -coverprofile cover.out

// Show coverage percentage
go tool cover -func cover.out
// Lint all application
golint ./...

// Examine Go source code and 
// reports suspicious constructs
go vet ./...

Usefull commands

goimports

gofmt

gobuild

go list

go run

go fix

go test

go clean

Usefull links

https://golang.org

https://gobyexample.com

http://golang-challenge.org

https://www.codewars.com

https://blog.golang.org

https://github.com/avelino/awesome-go

https://play.golang.org

Another cool side-projects

Smersh

souin-prestashop

Souin as prestashop module

Open-source pentest oriented platform to help pentester to get enhancement

github.com/CMEPW/Smersh

souin-wordpress

Souin as wordpress plugin

github.com/lucmichalski/prestashop-souin
github.com/darkweak/wordpress-souin

Thank you for your attention