Go
How to retrieve files using embed in Go
There are several ways to retrieve files in Go. You can use os.ReadFile() to read a file, or you can use the embed package to retrieve a file. Although used for slightly different purposes, using the embed package allows you to include files during the build, which is useful for distribution. Let’s take a simple example by creating a txt file as follows: hello.txtHello, World! Now, let’s retrieve this file using the embed package.
April 16, 2025
How to Send Form Data in the Body in Golang
While working, I encountered a situation where I needed to use an external API. Unlike the usual APIs that handle JSON or XML, I had to send and receive form data. Since I had only dealt with it during my time with JSP and had not used it much in my current industry, it had been a long time since I had used form data, and I was not well-versed in how to do it in Go.
April 14, 2025
Let's Translate All Posts Using AI in Hugo (feat. How My Blog Supports 5 Languages)
Task Recently, with the advancement of AI, I started using Gemini for work. Watching it handle unstructured data so well reminded me of the tearful tasks I once performed. Putting that aside, there has always been something that felt like a homework assignment to me. That is translating my blog. I heard that translating would attract many more readers to the blog, and there was a time when I considered using the Google Translate API to give it a try, but I ended up leaving it alone due to my laziness.
March 6, 2025
Rendering Mermaid Graphs in Hugo Blog
Currently, my tech blog uses a template engine called Hugo. Hugo is a static site generator that converts Markdown files into HTML. In Markdown, which we commonly use, there is a feature called code block. The Go code below is nicely highlighted syntax-wise: func main() { fmt.Println("Hello, World!") } Java code is likewise displayed with syntax highlighting through a code block:
March 6, 2025
Let's Learn About More Efficient State Management with FSM and Golang
Too Many States! When working in the industry, you begin to notice that there’s a state for even the smallest details. For example, there are states like user login status, order status, payment status, etc. These states are usually stored and managed in code or a database and are used to perform different logic based on the state. Prerequisite The data handled in REST is also related to state as it stands for Representational State Transfer, but this article will deal with a more narrow definition of state.
February 22, 2025
Let's Automatically Run Golang Tests and Generate Reports with Github Actions When Opening a PR
Automating builds or tests for any language, anywhere, is crucial. Although it’s possible to run tests locally and push them, sometimes people push without running tests. Hence, relying less on local tests and more on automation can be beneficial for long-term use and maintenance. In this post, we’ll explore how to create an action for testing in Golang and how to automatically run tests and generate reports when a PR is opened.
February 17, 2025
Let's Crawl Using Playwright in Golang
There are various ways to collect data, and the most common method is using a technique called crawling. Crawling, when translated literally, means to crawl. Web crawling can be thought of as collecting information by crawling the web. Tools Python is particularly widely used, not only because of its simplicity but also because there are many libraries specialized for crawling. Well-known tools include BeautifulSoup, Selenium, and Scrapy.
February 14, 2025
Testing in Golang Without Cache
When testing in Golang, the test speed becomes significantly faster from the second run. 1st Run ok github.com/my/package/test 126.752s 2nd Run ok github.com/my/package/test (cached) While the first run took over 2 minutes, the second run finished so quickly that there wasn’t even time to measure it.
February 14, 2025
Exploring the Difference Between log.Fatal() and panic() in Golang
“In this case, it seems better to use panic() over log.Fatal()” Recently, I received feedback like the one above while using log.Fatal(). Huh? Isn’t log.Fatal() just printing logs better? I thought. Embarrassingly, it was only recently that I clearly understood the difference between log.Fatal() and panic() in Golang, so I decided to take this opportunity to summarize it. Differences Between log.Fatal() and panic() Both log.Fatal() and panic() are functions that terminate the program. Let’s examine how they operate through code.
February 11, 2025
Building a Server Strong Against Duplicate Requests with Singleflight in Golang
Recently, my company went out of business, and I started working as a freelancer for a while. Fortunately, I met an excellent person and learned various skills regarding Go and the web, one of which was an improvement using the singleflight package. Singleflight? Literally translated, it means “single flight.” There’s no need to understand it too difficultly; just consider it as ensuring a single execution.
February 10, 2025
Experience Lombok in Golang
Lombok? Lombok is a library in Java that reduces repetitive code like getter and setter. Due to its characteristics, the Go language makes tasks like Getter, Setter, and constructor quite tedious. In languages like Java, there are libraries that automate these tasks. For instance, consider creating a constructor for a struct like the one below: type User struct { Name string Age int } Most of us would probably write a constructor like this:
October 24, 2023
Exploring the Difference Between Type Alias and Named Type (Golang)
Both are methods of redefining existing types when defining a new type, and are defined as follows: type MyStruct struct { Name string Age int } func(m MyStruct) Print(){ fmt.Println(m.Name, m.Age) } type MyStructNamed MyStruct // Named Type type MyStructAlias = MyStruct // Type Alias Type Alias In the case of a type alias, it assigns an alias to the existing type, so it has the same methods as the existing type.
October 13, 2023
Resolving Korean Character Corruption in CSV Files Exported from Golang
BOM Excel requires a BOM at the beginning of a file to correctly read a UTF-8 encoded CSV file. BOM: The Byte Order Mark (BOM) is the Unicode character U+FEFF byte order mark, and as a magic number, it is added at the very beginning of a document to convey various information to programs that read the text. In Code When using CSV in Golang, you can prevent Korean character corruption as follows.
September 23, 2023
Using Templates in Golang (Go Template)
Go Template Golang provides a feature called Go Template, which allows binding various data or exporting manipulated strings according to a specified format. text/template package This package is one of the two standard library packages used for processing text-based templates and is commonly used when text needs to be generated according to a fixed format or specific logic. An example of using the text/template package to export text according to a fixed format is shown below. package main import ( "os" "log" "text/template" ) type Person struct { Name string Age int } func main() { t := template.New("hello") t, err = t.Parse("Hello {{.Name}}, you are {{.Age}} years old.\n") if err != nil { log.Error(err) } p := Person{Name: "GiraffeWithCode", Age: 27} t.Execute(os.Stdout, p) } As seen in the code, it is easy to guess that each field like Name and Age in the Person struct will be bound to each element of the template string "Hello {{.Name}}, you are {{.Age}} years old.\n".
September 23, 2023