Category Archives: golang
How to make grpc call from shell
1 https://github.com/grpc/grpc/blob/master/doc/command_line_tool.md
1 |
grpc_cli call localhost:7020 ChatAPI.GetChats "external_user:{id:'30594028',type:1}, limit:10, offset:0, order:ORDER_DESC, requested_by_external_user:{id:'30594028',type:1},with_unread_count:true" |
2 https://github.com/fullstorydev/grpcurl
1 |
grpcurl -plaintext -emit-defaults -d '{"lozon_id": 15515160432000}' -H 'User-Name: grpcurl' localhost:7020 points/FindPointByLozonID |
How to analyze the performance of your go application in production
You should definitely use chi’s middleware for running pprof and stuff in your admin panel. That’s the repo — https://github.com/go-chi/chi That’s the profiler — https://github.com/go-chi/chi/blob/master/middleware/profiler.go CPU profiling After that you can run something like this in shell:
1 |
go tool pprof -png ~/Downloads/profile |
Or just open it in the browser:
1 |
go tool pprof -http=:1234 ~/Downloads/profile |
If it opens something different then your browser (sublime …
Using GOPROXY with go mod
1 |
GOPROXY=https://<some_url> go mod download |
Nice list of image resizer libs in go
With speedtests and other nice things. https://github.com/fawick/speedtest-resize I tried these two: https://github.com/disintegration/imaging https://github.com/bamiaux/rez They are quite the same talking about file sizes and imaging is muuch easier to use.
Mocking for testing go code
If you’re testing go code and have a huge API you have to mock, you have two options: make your dummy struct with embedded interface and implement only methods you need, or use your own interface that has only methods you need (and change your code to use that). For instance, I had amazon’s s3 …
BDD Framework For Golang
There is a good one: https://github.com/onsi/ginkgo It prefers to use http://onsi.github.io/gomega/ as a matcher.
Golang, PostgreSQL and array_agg
If you have SQL like this:
Container insights for golang engineer (k8s docker CPU throttling)
We’ve run into problems on my work when k8s limits cpu to few processors (throttling), while go application can see all of them (setting GO_MAX_PROCS to maximum CPUs available) and go’s scheduler is going crazy because of that during highload (like stress-tests). It is caused by scheduling for, let’s say, 40 processors while you have …
Особенности структур в go
Методы на структурах в golang определяются на типе. И если мы объявим типизированную переменную, даже не проинициализировав её, методы будут работать корректно до тех пор, пока мы не попытаемся обратиться к полям ресивера. Вот пример; первые два вызова работают нормально, третий валится с паникой.
GO. Реализация бинарного дерева
https://appliedgo.net/bintree/