Leinonen

Code, Mindfulness & Minimalism

Posts tagged with "go"

Found 4 posts.

August 1, 2025

Using SQLite with Go: Building a Flexible Database Abstraction Layer

Discover how to kickstart your new projects using SQLite with Go, and build a flexible database abstraction layer that allows you to seamlessly transition to any other database as your application scales. This blog post guides you through setting up SQLite for simplicity and speed, crafting an interface in Go for easy database swapping, and implementing it for different databases. Whether you're just starting or scaling up, ensure your application remains adaptable and robust.

Read more

September 21, 2025

Custom Unmarshallers in Go: Parsing Data Your Way

Discover how to leverage custom unmarshallers in Go to handle complex real-world data parsing challenges. This blog post explores the use of Go's json.Unmarshaler interface to transform inconsistent API data into clean, type-safe structures. Learn how to convert string values to enums, manage nested JSON objects, and implement validation directly in the unmarshalling process. With tips on performance, error handling, and testing, this guide helps you maintain clean and efficient code while managing messy external data formats. Perfect for developers looking to streamline data transformation in Go applications.

Read more

July 27, 2025

Avoid global state in Go

Avoid the pitfalls of using global state in Go by embracing a cleaner, more maintainable approach with structs and dependency injection. Global variables often introduce hidden dependencies, leading to tight coupling, race conditions, and poor testability. By encapsulating dependencies in structs and passing them explicitly, you can enhance code clarity, testability, and safety. This method allows for easier testing and a more organized code structure, ensuring your Go projects are robust and scalable. Say goodbye to global state and hello to a more reliable coding practice.

Read more

September 24, 2025

Building Safe SQL Queries in Go: A PostgreSQL Query Builder

Stop relying on string concatenation for SQL queries in Go and embrace a safer, more maintainable approach with a type-safe query builder. This blog post outlines the pitfalls of string concatenation, such as SQL injection risks and maintainability challenges, and introduces a robust query builder solution. Learn how this tool enhances security by using parameterized queries, improves readability with a fluent interface, and ensures type safety. Enhance your Go applications with secure, efficient, and easily testable SQL query construction.

Read more