Category Archives: golang

Useful links for proto generator development

https://rotemtam.com/2021/03/22/creating-a-protoc-plugin-to-gen-go-code/ https://medium.com/@tim.r.coulson/writing-a-protoc-plugin-with-google-golang-org-protobuf-cd5aa75f5777 https://github.com/nametake/protoc-gen-gohttp https://github.com/drekle/protoc-gen-goexample/blob/c60883c9711f3cfbd5191fd697651dbd067e6fdd/main.go#L135 https://github.com/grpc-ecosystem/grpc-gateway/blob/24434e22fb9734f1a62c81c4ea246125d7844645/examples/internal/proto/examplepb/echo_service_grpc.pb.go https://pkg.go.dev/google.golang.org/protobuf/compiler/protogen#Options.Run https://github.com/lyft/protoc-gen-star https://go.dev/blog/protobuf-apiv2 https://docs.buf.build/build/usage/#configuration https://github.com/grpc-ecosystem/grpc-gateway https://github.com/googleapis/googleapis/tree/master/google/api https://github.com/bufbuild/buf https://stackoverflow.com/questions/36540427/cannot-find-package-google-protobuf https://pkg.go.dev/google.golang.org/protobuf https://developers.google.com/protocol-buffers/docs/reference/go-generated#package https://stackoverflow.com/questions/61666805/correct-format-of-protoc-go-package https://grpc.io/docs/languages/go/quickstart/ https://github.com/protocolbuffers/protobuf/tree/master/src/google/protobuf https://github.com/gogo/protobuf/blob/b03c65ea87cdc3521ede29f62fe3ce239267c1bc/protobuf/google/protobuf/descriptor.proto

Go study

A list of resources for learning golang https://github.com/ardanlabs/gotraining/tree/master/reading

Nullable fields in json generated from protobuf file

Native support With grpc v2 for go, protofile’s optional option is supported, so you don’t need to import proto extensions anymore and use things like google.protobuf.StringValue. my.proto

go mapper

Legacy way with extensions Null for nil value my.proto

go mapper

Which will lead to this json response

Omit a field …

Read more

Talk about pros and cons of GraphQL

Pros: Very flexible — clients decide which fields of which entities they need. Documentation and test UI are available by default. Cons: Code looks ugly. N+1 selects problem is hard to solve (most probably — with some ad-hoc). It’s harder to test as you don’t know all the use cases. Not a binary protocol — …

Read more

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:

Or embedding one file directly into a variable:

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:

It does not have huge documentation, but it is written in golang, and you can check how the source …

Read more

Force ipv4 for golang http client

Sometimes you want to prevent your http client from using ipv6/tcp6. That’s how you do it.

Mocking for unit-tests and e2e-tests in golang

Some patterns to test your golang app. Mocking an interface

https://github.com/vektra/mockery Mocking SQL database

https://github.com/DATA-DOG/go-sqlmock Mocking HTTP server for unit-tests

https://golang.org/pkg/net/http/httptest/ Stubbing HTTP server for e2e-tests

https://github.com/jmartin82/mmock Mocking for e2e-tests with dockertest

https://github.com/ory/dockertest