Go Style Guide
Repository Go style defaults
Naming, error handling, logging, reconciler-safe concurrency, imports, and constants used across the repository.
Decision matrix
Default coding choices
| Area | Expected default | Avoid |
|---|---|---|
| Naming | Keep acronyms consistently cased and use direct Go-style getter names. | Mixed-case acronym spellings such as ServeHttp or getters such as GetStatus(). |
| Errors | Wrap returned errors with %w so callers keep context and error identity. | Returning opaque upstream errors with no explanation. |
| Logging | Use structured logr key-value logging. | fmt.Printf, log.Println, or string-built log lines that lose context. |
| Reconcilers | Keep work synchronous and requeue explicitly when you need another pass. | Unmanaged goroutines or time.Sleep in reconcile code. |
| Imports and constants | Use stable import grouping and name magic values explicitly. | Ad hoc import ordering and raw literals with unclear meaning. |
Naming
- Keep acronyms consistently cased:
ServeHTTP,ParseURL,userID. - Do not prefix getters with
Get. - Prefer
-ernames for single-method interfaces when the interface describes capability.
Errors and logging
Use wrapped errors and structured logging together. Most reviewer comments in this area come from missing context, not from complex logic.
if err := syncSecret(ctx, obj); err != nil {
return fmt.Errorf("sync secret for %s/%s: %w", obj.Namespace, obj.Name, err)
}
log.Info("reconciling cluster",
"cluster_namespace", req.Namespace,
"cluster_name", req.Name,
)
Do not log tokens, keys, passwords, or raw Secret data, even in debug-only paths.
Reconcile-safe concurrency
- Do not spawn unmanaged goroutines in reconcile code.
- Do not block workers with
time.Sleep. - Use
RequeueAfterwhen the controller should check again later.
Imports and constants
Group imports into three blocks:
- standard library
- third-party dependencies
- local
github.com/dc-tec/openbao-operator/...packages
Name important values explicitly instead of leaving raw numbers or suffix strings in logic.
Related standards
You are reading the unreleased main docs. Use the version menu for the newest published release, or check the release notes for what is already out.
Was this page helpful?
Use Needs work to open a structured GitHub issue for this page. The Yes button only acknowledges the signal locally.