How many times have you muttered under your breath while typing out Go struct tags by hand? I have worn out more than one keyboard doing it: you define a model, trigger tag generation in your editor, and it blindly stamps out the default json:"field" tag. Need db, yaml, or an omitempty flag? Back to manual typing.
In the latest update to the official gopls language server, the Go team finally expanded the "Add struct tags" Code Action. Instead of forcing a single format, the language server now opens an interactive popup menu in your editor so you can pick the exact set of tags you want.
You can check off multiple target serializers at once (for instance, json in camelCase and db in snake_case) and toggle automatic omitempty placement:
// Original struct before generating tags
type UserAccount struct {
UserID int64
UserEmail string
IsActive bool
}
Once you confirm your selection, gopls instantly generates consistent tags across the entire struct:
// Result of the interactive gopls Code Action
type UserAccount struct {
UserID int64 `json:"userId,omitempty" db:"user_id"`
UserEmail string `json:"userEmail" db:"user_email"`
IsActive bool `json:"isActive" db:"is_active"`
}
It is a small quality-of-life upgrade, but it saves hours of tedious typing and prevents silly typos in API field names.
