Author Archives: bullgare
Embedding assets to go binary in go 1.16
That’s how you can use it: package server import «embed» // content holds our static web server content. //go:embed image/* template/* //go:embed html/index.html var content embed.FS data, _ := f.ReadFile(«html/index.html») print(string(data)) Or embedding one file directly into a variable: import _ «embed» //go:embed hello.txt var s string print(s) More details — https://golang.org/pkg/embed/
mmock for mocking microservices
It is a very easy to set up though pretty powerful tool with support for delays and handling query params. It also has a console for checking all the requests and corresponding responses matched. Here it is https://github.com/jmartin82/mmock. Below I describe a way to use it with docker-compose for local development.
Forward multiple kubernetes pods for local development
kubefwd is a great tool that can forward a lot of pods at once to your local machine. The only downside for me is that it touches your local `/etc/hosts`. That’s how I use it: sudo KUBECONFIG=<path to your k8s config> kubefwd svc -l «app in (first-api, second-api, third-service)» It does not have huge documentation, …
XDebug inside a docker container
That’s how you can debug your php app running in a docker container.
Force ipv4 for golang http client
Sometimes you want to prevent your http client from using ipv6/tcp6. That’s how you do it. dialer := &net.Dialer{ Timeout: dialTimeout, KeepAlive: keepAliveTimeout, } transport := &http.Transport{ Proxy: http.ProxyFromEnvironment, ForceAttemptHTTP2: false, DialContext: func(ctx context.Context, network string, addr string) (net.Conn, error) { ipv4, err := resolveIPv4(addr) if err != nil { return nil, err } return …
Mocking for unit-tests and e2e-tests in golang
Some patterns to test your golang app. Mocking an interface mockS3 := &mocks.S3API{} mockResultFn := func(input *s3.ListObjectsInput) *s3.ListObjectsOutput { output := &s3.ListObjectsOutput{} output.SetCommonPrefixes([]*s3.CommonPrefix{ &s3.CommonPrefix{ Prefix: aws.String(«2017-01-01»), }, }) return output } // NB: .Return(…) must return the same signature as the method being mocked. // In this case it’s (*s3.ListObjectsOutput, error). mockS3.On(«ListObjects», mock.MatchedBy(func(input *s3.ListObjectsInput) bool …
Install go2 beta on MacOS
A quick guide on installing golang v2 development revision. It works for my MacOS Big Sur (with an Intel processor).
Using DataDog on your CentOs
DD_AGENT_MAJOR_VERSION=7 DD_API_KEY=<your-key> DD_SITE=»datadoghq.eu» bash -c «$(curl -L https://s3.amazonaws.com/dd-agent/scripts/install_script.sh)» sudo nano /etc/datadog-agent/datadog.yaml # uncomment logs_enabled: true sudo systemctl restart datadog-agent sudo mkdir /etc/datadog-agent/conf.d/go.d sudo nano /etc/datadog-agent/conf.d/go.d/conf.yaml # and add contents from the url below https://app.datadoghq.eu/logs/onboarding/server https://docs.datadoghq.com/agent/faq/error-restarting-agent-already-listening-on-a-configured-port/ Or, if you want a dockerized version of DataDog agent, and you want to listen to docker logs, you can …
Install go with gvm on MacOS Big Sur
I used to use gvm for this — https://github.com/moovweb/gvm. But initial installation of go from scratch does not work for Big Sur as 1.4 does not have a binary for this OS (this command fails — gvm install go1.4 -B). To use gvm, you can do this: 0. Install gvm — bash <
Use brew cask to install software on MacOS
That’s the way to automate your favorite apps installed on a new machine with one command and a config file. https://github.com/Homebrew/homebrew-cask. You can either install apps manually with a command like brew cask install goland or install all your apps by provided config. One downside is that it has a limited list of apps supported …