ALL
The Significant Impact of Porting TypeScript to Go
In March, a significant announcement was made: the official plan to port TypeScript to Go, claiming a tenfold performance improvement.From the perspective of a language server developer, this project holds substantial implications, particularly in enhancing AI-assisted programming.TypeScript Users: Smoother Programming Experience and Build SpeedThe community has debated the choice of language for this transition. Some argue Microsoft should have opted for its own C#, while others suggest Rust, aligning more closely with the modern frontend ecosystem. The official decision considered the costs ...
1,724 1 MICROSOFT GOLANG TYPESCRIPT
One-function Interfaces in GoLang
Saw a GoLang pattern where a function itself implements an interface—meaning the function alone is the implementation of the interface. It took me a while to figure this out when I first encountered it, so I’m recording it here.Take server.go from the GoLang standard library as an example. The Handler interface is defined as follows:type Handler interface { ServeHTTP(ResponseWriter, *Request)}If we want to define a Handler, we would typically write:// Define a structtype MyHandler struct{}// Implement the http.Handler interface methodfunc (h MyHandler) ServeHTTP(w http.ResponseWrit...
2,822 0 GOLANG ONER FUNCTION INTERFACE
Calculating Token Count for Claude API Using Go: A Step-by-Step Guide
When working with large language models like Claude from Anthropic, understanding how many tokens your input consumes is essential for managing costs and optimizing performance. In this blog, we’ll explore how to calculate token counts for a given input using Go. We’ll use Anthropic’s count_tokens API endpoint, which provides a straightforward way to determine token usage.PrerequisitesBefore diving in, ensure you have:A working Go environment (installation guide).An Anthropic API key. Set it as an environment variable (ANTHROPIC_API_KEY).Basic knowledge of Go HTTP requests an...
Gemini Example with Go
To connect and use Gemini with Go, Google's LLM, one can use their official Go SDK for doing this. In this post, we will just show a simple chat example to demonstrate how to make it work with Go.The example is just to ask the model to translate some English to Chinese and get its output. The code actually looks like:var client *genai.Client// geminiOnce.Do(func() {client, err = genai.NewClient(ctx, option.WithAPIKey(string(apiKey)))if err != nil { log.Fatal(err)}model := client.GenerativeModel("gemini-1.5-flash-latest")model.SetTemperature(0.1)resp, err := model.GenerateContent(ctx, genai.Tex...
1,999 2 EXAMPLE GO TRANSLATION GOLANG GEMINI
The Missing Session Cookie While Using GoLang Gin
Gin is a widely used web framework in Go, offering powerful features to streamline website development. Among its many capabilities, handling sessions and cookies is a critical aspect for building functional web applications.This post highlights a behavior in the Gin framework that may not be immediately obvious or intuitive—the missing session cookie issue.So, what exactly is the missing session cookie issue? It occurs when a session is created and saved in one route but isn’t accessible in other routes. Additionally, the expected session cookie with the specified key is not prese...
Why is Golang's Compilation Speed So Fast?
OverviewWhen I started learning the Go language, I already had experience with three statically typed languages—C/C++ and Java—and two dynamically typed languages—PHP and JavaScript. Because of this background, when I compiled a demo file of several hundred lines for the first time in Go, I was genuinely impressed by its compilation speed. At that moment, I thought to myself, "Go claims to have the execution speed of statically typed languages and the compilation speed of dynamically typed languages—it indeed lives up to its reputation." Indeed, one of the primary motiv...
4,117 1 GO GOLANG COMPILATION
Introduction to the Application of eBPF in Golang
Most of the time, when we develop software or even use software, we play within the safe boundaries of the operating system. We might not know how the network interface welcomes that IP packet, nor how the filesystem handles the inodes when we save a file.This boundary is called user space, which is where we write applications, libraries, and tools. But there's another world, kernel space, where the operating system's kernel resides and is responsible for managing system resources such as memory, CPU, and I/O devices.We usually don’t need to go below the socket or file descriptor level, ...
2,661 0 APPLICATION GUIDE GOLANG EBPF
GoLang Interview Questions
Below lists some frequently asked GoLang interview questions and their corresponding answers based on the author's experience. The list is updated frequently with new understandings. Stay tuned.What is the GMP model of GoLang?GoLang uses goroutine to achieve concurrency and it is famous for high concurrency support as the language defines its own goroutine dispatching and processing system which is well known as GMP model.How it works is that M is normally defined as the OS thread being spawned( then each M thread should be associated with a Process queue and each Process queue can have multip...
1,375 0 MEMORY CONCURRENCY INTERVIEW QUESTION GOLANG