Blog

Best Practices for Wrapping CPP Library with CGO

Background Recently, our business needed to reuse a client SDK library written in CPP. To enable our team’s primary language, Golang, to seamlessly integrate with this SDK, we used CGO bridging technology to wrap the C++11 SDK library into a production-ready Golang SDK. After reviewing most of the online resources about CGO in both Chinese and English, I found there are many important details to consider when implementing Go calls to CPP libraries. Most Chinese materials only briefly mention simple examples of wrapping C++ STL library functions. Building on previous work, this article summarizes a series of best practices for wrapping complex CPP libraries, aiming to fill the gap in related documentation.

Read more →

March 27, 2022

Memory Leak Caused by Using Go STL to Query DB

Problem Origin Recently, a Go API service was found to have continuously increasing memory usage through regular monitoring. The memory usage rose from the initial 70MB to over 1GB until it ran out of memory and crashed. This clearly indicated a memory leak issue. Since memory leaks rarely occur in languages with built-in garbage collection, if there is one, it must be a significant problem. Therefore, the following detailed investigation process was carried out to accumulate experience for handling similar issues in the future.

Read more →

March 6, 2020

Golang Common Concurrency Patterns

Concurrency patterns are one of Go’s most distinctive programming paradigms. This article summarizes the most common concurrency patterns in Go development, including request-receiver pattern, single state holder pattern, producer-consumer pattern, Pipeline pattern, and more. These patterns help us better organize and manage goroutines, making concurrent programs more robust and elegant. By learning these patterns, you’ll be able to better master Go’s concurrency features and write higher quality concurrent code.

Read more →

September 22, 2019