Microservices
-
How I’m writing Serverless services in Golang
Service discovery allows you to register the location of services, with a user friendly name, so that you can find other services by name. AWS provides a Serverless offering for this, called Cloudmap
The most important lesson I hope you take away from this, however, is protecting your business logic from the sea of AWS services and technologies. Treat Lambda as an unimportant detail, treat DynamoDB as an unimportant detail
-
Make resilient Go net/http servers using timeouts, deadlines and context cancellation Initialize
net/http
server with timeouts:1 2 3 4 5 6 7 8
srv := &http.Server{ ReadTimeout: 1 * time.Second, WriteTimeout: 1 * time.Second, IdleTimeout: 30 * time.Second, ReadHeaderTimeout: 2 * time.Second, TLSConfig: tlsConfig, Handler: srvMux, }
- the
net/http
packages provide aTimeoutHandler
- it returns a handler that runs a handler within the given time limit
- use
Context
to be aware of request
- the
AppSec
Beyondcorp
-
ORY is the open source and cloud native identity infrastructure. ORY is written in Go and open standards and consensus are the foundation. It is language and platform independent, extremely lightweight, starts up in seconds and doesn’t interfere with your code
Inspired by Google’s BeyondCorp
TODO ory ecosystem
AWS
- API Gateway Authorizer Blueprint in Golang
- API Gateway Custom Authorizer
- A simple AWS API Gateway Authoriser in Go
- expressive DynamoDB library for Go
CDK
- Getting started with CDK and Golang
- Using AWS CDK to configure deploy a Golang Lambda with API Gateway
Books
Configuration
Spacemacs
Pre-requisites to use the go-layer inside spacemacs
:
|
|
doom emacs
GTAGS
gtags
will create CTAGS
files to global. For Go you can use gogtags to
generate the files. It also works well with helm-gtags.
Code Examples
Code Style
- Cleaner go code with golines
- Effective Go (golang.org)
- Darker Corners of Go
- covers most of the 101 topics beginners should know about Golang
Clean Code Examples
- github.com/ahmetb/kubectx
- github.com/gojek/heimdall
- github.com/ethereum/go-ethereum
- github.com/drone/drone
- github.com/google/exposure-notifications-server
Design
Fun
Internals
- A recap of request handling in Go
- Diving deep into net/http : A look at http.RoundTripper
- Dissecting golang’s HandlerFunc, Handle and DefaultServeMux
- Requests richtig verarbeiten: Keine Sorge beim Multiplexen in Go
- How to handle signals with Go to graceful shutdown HTTP server
- Life of an HTTP request in a Go server - Eli Bendersky’s website
Context
-
Context provides a means of transmitting deadlines, caller cancellations, and other request-scoped values across API boundaries and between processes. It is often used when a library interacts — directly or transitively — with remote servers, such as databases, APIs
When designing an API with context, remember the advice: pass
context.Context
in as an argument; don’t store it in structs.
Interviews
Messaging
Bots
Slack
- slack-go/slack examples
- Create a Slack bot using Golang
- Write an interactive message bot for Slack in Golang
- full code: go-slack-interactive
- bot tokens
- slack-message-builder
- message attachments
- block kit builder
- Frameworks
- github.com/go-chat-bot/bot
- IRC, SLACK, Telegram and RocketChat bot written in Go
- github.com/alexandre-normand/slackscot
- Slack bot core/framework written in Go with support for reactions to message updates/deletes
Malware
Modules
- How I Structure Go Packages Some great advice about logging and package structure
- Go best practices, 6 years in
Testing
- Learn go with test-driven development (TDD)
- Testing Go services using interfaces (deliveroo)
- Building and Testing a REST API in GoLang using Gorilla Mux and MySQL
- Testing with GoMock: A Tutorial - codecentric AG Blog
- GoMock vs. Testify: Mocking frameworks for Go
- learn how to use
mockery
andtestify
- 3 classes fo failures:
- Unexpected calls
- Missing calls (expected, but not occurred)
- Expected calls with unexpected parameter values
- learn how to use
- Golang basics - writing unit tests
- Testing HTTP Handlers in Go
- Testing Clients to an HTTP API in Go
- Writing good unit tests for SOLID go
- structs will depend on interfaces instead of structs (easy for dependency injection)
- What should be tested:
- when testing, you can think of it as sending and receiving messages
- incoming messages refer to calls to methods
- outgoing messages refers to calls from the tested object on its dependencies
- most people go first to integration tests
- Testing Go at Stream
- Using Go Interfaces for Testable Code - The Startup - Medium
- using interfaces for stubbing
- 2020-05 | How I write my unit tests in Go quickly
- on dependency injection
- duck typing interfaces
- BDD (Behaviour Driven Development)
Fuzzing
TDD
- More on TDD
Great resources:
- github.com/quii/learn-go-with-tests
- leanpub.com/golang-tdd/read
- really good explanations
Tools
-
gojson: Automatically generate Go (golang) struct definitions from example JSON
-
go-spew: Implements a deep pretty printer for Go data structures to aid in debugging
-
Godocgen is an app built using Go programming language to generate Go module package’s documentations. It parses the packages documentation data and facilitates custom rendering, enabling Gopher to use other hosting solution like Hugo to host the documents.
-
3mux: Terminal multiplexer inspired by i3
-
tspur: Terminal Screen with Protected User Records (TSPUR)
-
- This tool instantly converts JSON into a Go type definition
Templates
Logging
-
About Go logging for reusable packages
Use some global variadic function:
1 2 3 4 5
package mypkg // LogFunc is a function that logs the provided message with optional // fmt.Sprintf-style arguments. By default, logs to the default log.Logger. var LogFunc func(string, ...interface{}) = log.Printf
-
- Some tips:
- Never log in a package that isn’t main
- Don’t log things if the program is operating normally
- only log in package main
- Some tips:
OO
Packaging
- Zombie Zen - How I packaged a Go program for Windows and Linux
- Packages as layers, not groups
- How to think of your modules as layers and not as groups
- by Ben Johnson (wo wrote the standard package layout)
- How to Structure a Go Command-Line Project
- Go best practices, six years in
Serialization
-
- Nice elegant solution using aliases, e.g.
1 2 3 4 5 6 7 8 9 10
func (u *MyUser) MarshalJSON() ([]byte, error) { type Alias MyUser return json.Marshal(&struct { LastSeen int64 `json:"lastSeen"` *Alias }{ LastSeen: u.LastSeen.Unix(), Alias: (*Alias)(u), }) }
-
Golang JSON Serialization With Interfaces
- Working with plants and animals
- adds extra field
type
to know which struct to use
-
Is there a way to have json.Unmarshal() select struct type based on “type” property?
- how to do deserialization when field is a list of interfaces
- implement
UnmarshalJSON
on slice of interfaces - Example with []vehicle
Security
- Security assessment techniques for go projects
- static analysis, fuzzing, dynamic testing etc.
- CSRF Attacks
- Implementing CSRF, auth handler
Pentest
- github.com/sysdream/hershell
- github.com/sysdream/chashell
- using DNS as reverse shell
- github.com/sysdream/ligolo
Botnets
- github.com/gnxbr/Unbreakable-Botnet-C2
- using Blockchains for communication channel
Scanners
Surveys
UI
- Vugu
- A modern UI library for Go+WebAssembly