FAQ

  • go-micro service interactions

    Image of micro-interactions

  • How to download all dependencies after cloning the repo?

# by default this will download all modules in go.mod
go mod download
# with golang 1.14, some modules are not compatible yet. please use this as temp solution.
go env -w GOPROXY=direct
go env -w GOSUMDB=off
go mod download
# If you are importing internal/private modules, use following setting with `go mod download`
GOPRIVATE=bitbucket.com/banzaicloud/*
go mod download
  • How to use go modules from a Fork and branch

    To use a fork, e.g., https://github.com/drnic/fatih-color, and a branch silly-changes, You need to update go.mod to use the replace helper:

    module github.com/starkandwayne/my-go-project
    
    go 1.14
    
    require (
      github.com/fatih/color v1.7.0 // indirect
      github.com/mattn/go-colorable v0.1.2 // indirect
    )
    
    replace github.com/fatih/color => github.com/drnic/fatih-color silly-change
  • How to update 3rd party dependencies?

    go get -u # to use the latest minor or patch releases
    go get -u=patch # to use the latest patch releases
    go mod tidy
    # to find out why you have specific dependency
    go mod why -m github.com/DATA-DOG/go-sqlmock
    # if you want to get binaries into $GOHOME/bin or $GOBIN
    GO111MODULE=off go get whatever
    # list modules
    go list -m all
  • How to get commitizen and cz-conventional-changelog work for non-node-git-repo?

    You can get commitizen and cz-conventional-changelog work for non-node-git-repo with global installation. Here are the steps that I have followed.

    yarn global add commitizen cz-conventional-changelog
    echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc; # create .czrc
    cd non-node-git-repo
    touch foo
    git cz -a
  • How to clean cached go modules?

    rm go.sum
    go clean -modcache
    go mod download
    # this empties $GOPATH/pkg/mod/
    go clean -cache -modcache
  • How to Prepare for a Release?

    go mod tidy
    go test all
  • how to debug in VS Code?

    every time, make sure file with main() is opened before proceeding to next steps

    1. open GoLang file with main() method you want to debug.

    2. click on debug icon in Action Bar

    3. click on Launch [▶] button.

    4. Optionally edit .vscode/launch.json and add args, env etc.

  • How to implement integration tests?

Integration tests are e2e tests that invoke Handler methods directly and ignore networking completely. True e2e tests are Black-box tests that invoke network endpoint.

Notice the last test has the convention of:

  • using Integration in the test name.

  • checking if running under -short flag directive.

Basically, the spec goes:

"write all tests normally. if it is a long-running tests, or an integration test, follow this naming convention and check for -short"

When we want to run our unit tests, we would use the -short flag, and omit it for running our integration tests or long running tests.

Use t.Errorf t.Logf for logging. don't use logrus or default log

  • How to ssh and debug a scratch container?

    Ephemeral containers are a great way to debug running pods, as you can’t add regular containers to a pod after creation. These containers executes within the namespace of an existing pod and has access to the file systems of its individual containers.

  • How to debug a pod that is crashing during initialization? If you pod crashing you cannot SSH to it, e.g., to see file system etc. Assuming your container has busybox at /bin/busybox, add following command to your deployment yaml.

    Then run kubectl exec -it $POD_NAME -- /bin/busybox sh to SSH to the container.

  • Why some ORM model fields are pointers?

    all fields having a zero value, like 0, '', false or other zero values, won’t be saved into the database but will use its default value. If you want to avoid this, consider using a pointer type or scanner/valuer, e.g:

    Note: google wrapper types google.protobuf.StringValue, .BoolValue, .UInt32Value, .FloatValue, etc. map to pointers of the internal type at the ORM level, e.g. string, bool, uint32, float

  • How to run go-micro gRPC services and Micro REST Gateway on k8s?

    So you want to use k8s internal CoreDNS as service registry?, then you have to follow some rules:

    • Service name cannot have .(dot) due to k8s DNS limits, so make it simple via environment variables e.g., MICRO_SERVER_NAME=account

    • custom build REST Gateway as micro/micro:latest image is outdated. optionally add CORS plugin.

  • performance If you’re concerned about performance, try

    You can now enable profiling in go-micro by setting MICRO_DEBUG_PROFILE=true This will enable pprof and write a cpu profile and heap profile to /tmp the profiles will be [service name].{cpu, mem}.pprof

  • How to rollback a git commit?

  • How to Push Git Tags with Commit? Refer: how-to-push-git-tags-with-commit

  • How to debug etcd?

Refer

Last updated

Was this helpful?