Author Archives: bullgare
MGTS(GPON)+Keenetic and external access to Synology
Adding a comment to an article about using Keenetic router behind an MGTS(gpon) receiver to make Synology services like DS Audio/Video/Photo and so on to be available via Quickconnect feature by Synology. First of all, enable KeenDNS like shown below And then enable it on Synology Control Panel like this: And now on any device …
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
Set github actions for you repo
If you want to run tests/linters against you golang project, place something like the example below in .github/workflows/somename.yml to your project:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
name: ci-cd on: push: branches: - '**' env: GONOSUMDB: "github.com/<your-organization>" GOPRIVATE: "github.com/<your-organization>" jobs: ci-cd: strategy: matrix: go-version: [ 1.16.x ] runs-on: ubuntu-latest steps: - name: Install Go uses: actions/setup-go@v2 with: go-version: ${{ matrix.go-version }} - name: Write .netrc for private go modules env: NETRC_USER: ${{ secrets.NETRC_USER }} NETRC_PASS: ${{ secrets.NETRC_PASS }} run: echo "machine github.com login ${{ secrets.NETRC_USER }} password ${{ secrets.NETRC_PASS }}" > $HOME/.netrc - name: Checkout the code uses: actions/checkout@master with: fetch-depth: 1 - name: Run Makefile::ci-cd-check run: make ci-cd-check |
Good article on that — https://github.com/mvdan/github-actions-golang
Postgresql exercises
Basic querying — https://pgexercises.com/questions/basic/. Joins — https://pgexercises.com/questions/joins/. Data modification — https://pgexercises.com/questions/updates/. Aggregations — https://pgexercises.com/questions/aggregates/. That could be useful to refresh your memory. Not really up-to-date, but still pretty useful.
Mac OS — decrease pdf size via Preview app
To decrease the size of the .pdf filled with images, in Preview you can go to Export and set Quartz Filter→Reduce File Size before saving. If the images are too blurry for you, you can add your own profile. 1. Create a directory — /Library/Filters. 2. Add new filter file with unique filter — i.e. …
Parental control for Linux Mint
Time limiter with UI — Timekpr (https://www.linuxuprising.com/2019/11/timekpr-next-is-linux-parental-control.html) Domain blocker — Mintnanny (https://www.reallinuxuser.com/how-to-setup-parental-control-in-linux-mint/), too simple.
Shell: repeat a task multiple time
All shells (bash/zsh):
1 |
watch -n 3 "curl --location --request GET 'http://...'" |
will run curl every 3 seconds until you break it. zsh specific:
1 |
repeat 5 { curl --location --request GET 'http://...' } |
will repeat it 5 times without any delay
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
1 2 3 |
message FeeView { optional string name = 1 [json_name = "name"]; } |
go mapper
1 2 3 4 5 6 7 8 |
var name *string if fee.Name != nil { name = &fee.Name } fee := &desc.FeeView{ Name: name, } |
Legacy way with extensions Null for nil value my.proto
1 2 3 4 5 |
import "google/protobuf/wrappers.proto"; message FeeView { google.protobuf.StringValue name = 1 [json_name = "name"]; } |
go mapper
1 2 3 4 5 6 7 8 9 10 11 12 |
import "github.com/gogo/protobuf/types" var name *types.StringValue if fee.Name != nil { name = &types.StringValue{ Value: *fee.Name, } } fee := &desc.FeeView{ Name: name, } |
Which will lead to this json response
1 |
{"translation_key":"a fee","name":null,"value":5,"style":"body","text_color":"grey","tag":null} |
Omit a field …
Using tcpdump for k8s pods
You need wireshark to be installed on your local machine — download (more on this below). If you don’t have tcpdump installed inside the pod, you can install it with
1 2 3 4 5 |
# get pod name kubectl get po -Lversion,cfg,infra-cfg -lapp=<pod-tag> kubectl exec -it <pod-name> sh # inside the pod, alpine apk add tcpdump |
Then, on your local machine:
1 |
kubectl exec <pod-name> -- tcpdump -i eth0 -w - | wireshark -k -i - |
If you want to see packets in grpc/http2, you can add a rule in Wireshark. For this, click …