Category Archives: Programming

Datadog in a docker for integration tests and local dev

DOCKER_CONTENT_TRUST=1 docker run —rm —name dd-agent -p 8126:8126 -v /var/run/docker.sock:/var/run/docker.sock:ro -v /proc/:/host/proc/:ro -v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro -e DD_API_KEY=REPLACE_WITH_NEW_KEY -e DD_SITE=datadoghq.eu datadog/agent

Debugging go app in Jetbrains Goland on m1

First download a proper version of GoLand here — select .dmg (MacOS Apple Silicon) here (direct link — https://www.jetbrains.com/go/download/download-thanks.html?type=eap&platform=macM1&build=211.6556.11&code=GO). Then make sure you are using arm version of go (go version go1.16.2 darwin/arm64). If not, download and install arm version of golang (like «go1.16.2.darwin-arm64.pkg») from the list here — https://golang.org/dl/. Now it should work. With …

Read more

Example of using embed in go

Nice article on using go templates with embed introduced in go1.16: https://philipptanlak.com/web-frontends-in-go/. That’s the code:

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/

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, …

Read more

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 …

Read more

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 …

Read more

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 …

Read more