go

How to compile Go apps with no source code and only .a files

Last weekend, a Gopher shared a problem with me regarding the compilation of Go programs. His request, which was not complicated at all, was that the API package provided by the partner company included only the golang archive (.a file built with go build -buildmode=archive), and no source code for the Go package. How can I link this .a to the final executable program built by the project? For C, C++, Java programmers, only provide static link library or dynamic link library (including header files), jar file without providing the source code of the API is very common.

Configuration Management for Golang Applications

Typically, our applications involve a number of configurations, such as HTTP/RPC listening ports, logging-related configurations, database configurations, and so on; these configurations can come from a variety of different sources, such as local configuration files, environment variables, command line arguments, or remote configuration centres such as Consul. A configuration can exist in several different sources at the same time and needs to be prioritised. This article describes the use of koanf for configuration management in Golang applications.

Performance Impact of Pre-allocating Slice Memory in Golang

When I review code, I often focus on whether the initialization of slice in the code allocates the expected memory space, i.e., anything that var init []int64 I ask to change to init := make([]int64, 0, length) format as much as possible. But there’s no quantitative idea of how much of an impact this improvement will have on performance, it’s just dogmatically required. This blog will go over the theoretical basis for preallocated memory to improve performance, quantitative measurements, and tools to automate detection and discovery.