Go does not ship a data governance framework. It gives you strong typing, the database/sql package, encoding/json, log/slog, and context, and you build governance (ownership, validation, retention, access control and auditing) on top of them. The practical approach is to model data with explicit types, validate at the boundary, keep every database access behind a small repository, record who changed what, and delete data on a schedule.
Data management is how you store, move and query data. Data governance is the set of rules around it: who owns it, who may read it, how long it lives, and how you prove that rules were followed. Both are mostly design decisions, and Go's simplicity makes those decisions easy to enforce in code.
Governance starts with knowing what your data is. Give each concept its own type instead of passing string and map[string]any around. Distinct types make it hard to mix up an email address and a display name, and they give you one place to validate.
Validate once, at the edge of your system (HTTP handler, queue consumer, CLI), and pass only valid types inward. Return all validation problems together with errors.Join so callers can report them at once.
Never let handlers build SQL strings. A repository interface keeps queries, transactions and access rules in one package, which makes review and auditing simple. Always pass context.Context so that timeouts and cancellation reach the database, and always use parameterised queries.
Wrap multi-step changes in a transaction with db.BeginTx(ctx, nil) and roll back on any error, so a failure never leaves half-written data. Set SetMaxOpenConns, SetMaxIdleConns and SetConnMaxLifetime on the pool so the service cannot overload the database.
Schema changes are a governance concern: they must be reviewed, ordered and reversible. Keep migrations as numbered SQL files in the repository and apply them with a tool such as golang-migrate, goose or Atlas. Embed them with //go:embed so the binary carries the exact schema it expects.
Run migrations from a separate command or job rather than on every application start, so that a rolling deploy of several replicas does not race on the same change.
An audit trail answers who did what, to which record, and when. Use the standard log/slog package with structured fields, and write audit events to a stream that application code cannot edit afterwards.
Log identifiers, not the sensitive values themselves. To make that automatic, implement slog.LogValuer on types that hold secrets so they print as a placeholder:
Classify fields (public, internal, personal, secret) and decide which roles may read each class. In Go this is usually a check in the service layer, driven by the caller's identity stored in the request context.
| Class | Example | Rule |
|---|---|---|
| Public | product name | Anyone may read |
| Internal | order status | Authenticated staff and owners |
| Personal | email, phone | Owner and support role, logged on access |
| Secret | password hash, tokens | Never returned or logged |
Return dedicated response structs instead of the database model, so adding a column never leaks it by accident. Use json:"-" on fields that must never be serialised.
Data you no longer need is a liability. Define a retention period per data class and enforce it with a scheduled job that deletes or anonymises old rows in batches.
Soft deletion (a deleted_at column) is useful for recovery, but pair it with a hard purge so records do not live forever. Remember backups and search indexes when you promise deletion.
No. The standard library supplies the building blocks (database/sql, slog, context, encoding/json), and you add policies in your own packages or with libraries for validation and migrations.
Implement slog.LogValuer on secret types, log IDs instead of values, and never log whole request or response bodies.
Either works. What matters is that all access goes through one reviewed layer with parameterised queries, context timeouts and transactions. Tools such as sqlc generate type-safe code from plain SQL.
Log the deletion event with the record ID and time in your audit stream, and run purge jobs on a schedule that you monitor. Document how backups age out.
Treat governance as code: typed models validated at the boundary, one repository layer using context and parameterised SQL, versioned migrations, structured audit logs with redaction, explicit access rules per data class, and scheduled retention jobs. Go gives you the primitives, and your team defines and tests the policies.