
July 25, 2026
10 HTML Tricks Experts Use That You Can Start Using Today
Discover ten lesser-known HTML features that solve real problems without JavaScript. From native modals to semantic progress indicators, these patterns...
Artikel lesen
Blog-Artikel
Go (Golang) is famous for its simplicity, speed, and reliability.
readytools
July 1, 2026
3 Min. Lesezeit
Image source: encrypted-tbn0.gstatic.com
Teilen
Go (Golang) is famous for its simplicity, speed, and reliability. But even with its clean syntax, there are plenty of practical tricks that can save you time, reduce bugs, and make your code more idiomatic. Here are 10 of the most useful Go tricks that seasoned developers use to write cleaner, faster, and more maintainable code
go run . and Build Tags for Quick IterationForget typing long go run main.go commands. Just run:
go run .For even more power, use build tags to toggle features during development:
// +build debug
package mainOr with the modern syntax:
//go:build debugThis lets you keep debug code without polluting production builds.
embedSince Go 1.16, embedding files is built-in and incredibly useful for CLIs, web servers, or templates:
import "embed"
//go:embed templates/*
var templates embed.FS
//go:embed static/*
var static embed.FSNo more external dependencies or complex asset pipelines. Perfect for single-binary deployments.
Instead of massive config structs or many constructor variants, use the Functional Options pattern:
type Server struct {
addr string
port int
tls bool
}
type Option func(*Server)
func WithTLS() Option { ... }
func NewServer(opts ...Option) *Server {
s := &Server{addr: "localhost", port: 8080}
for _, opt := range opts {
opt(s)
}
return s
}Clean, extensible, and very idiomatic.
context.Context Everywhere (and Proper Cancellation)Always pass context.Context to functions that might be long-running or network-bound. Use context.WithTimeout or context.WithCancel liberally:
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()This one habit prevents many goroutine leaks and makes your services more resilient.
Don’t fear generics. They shine for utilities like maps, sets, or data processing:
func Map[T, U any](slice []T, fn func(T) U) []U {
result := make([]U, len(slice))
for i, v := range slice {
result[i] = fn(v)
}
return result
}Use them judiciously—don’t over-engineer, but they can eliminate a lot of copy-paste code.
sync.Once for Lazy InitializationNeed to initialize something exactly once across goroutines? sync.Once is perfect:
var (
once sync.Once
db *sql.DB
)
func getDB() *sql.DB {
once.Do(func() {
db = connectToDB()
})
return db
}Simple, thread-safe, and cleaner than sync.Mutex + double-checked locking.
%w and errors.Is / errors.AsAlways wrap errors for better debugging:
return fmt.Errorf("failed to fetch user %d: %w", id, err)Then check them properly:
if errors.Is(err, sql.ErrNoRows) { ... }This gives you rich error context without losing the original error type.
strings.Builder and bytes.Buffer WiselyFor performance-critical string building:
var b strings.Builder
for _, item := range items {
b.WriteString(item)
b.WriteByte(',')
}
result := b.String()Much more efficient than repeated += operations.
t.Run for SubtestsLevel up your testing:
func TestProcess(t *testing.T) {
tests := []struct{
name string
input string
want int
}{ ... }
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// test logic
})
}
}This keeps your tests organized and makes failures easy to pinpoint.
go:generate for Code GenerationAutomate repetitive tasks with //go:generate:
//go:generate stringer -type=Status
//go:generate mockgen -source=repository.go -destination=mock.goCombine it with tools like wire, mockgen, or custom generators to keep your code DRY.
Bonus Tip: Get comfortable with go vet, staticcheck, and golangci-lint. Running a good linter locally (and in CI) catches many issues before they become problems. Go rewards simplicity and explicitness. These tricks help you stay in that sweet spot: expressive code that’s still fast and easy to reason about.
Entdecke ReadyTools: die ultimative Produktivitätssuite für Creator. Wunderschöne Linksy-Seiten, smarte Lara-KI, Projektmanagement, sicherer Cloud-Speicher und alles andere, was du brauchst – vereint an einem Ort. Starte noch heute deine 7-tägige kostenlose Testphase.
ReadyTools erkundenInhaltsverzeichnis
Weiterlesen

July 25, 2026
Discover ten lesser-known HTML features that solve real problems without JavaScript. From native modals to semantic progress indicators, these patterns...
Artikel lesen

July 24, 2026
The new Boards block brings Kanban-style project management directly into Workspace pages, supporting hundreds of cards, nested content, and full...
Artikel lesen

July 23, 2026
From synchronization engines to suggestion modes, the July 14-21 updates show what happens when a collaborative editor invests in the layers users rarely..
Artikel lesen