Go Style Guide¶
General Go coding style and conventions for the OpenBao Operator.
1. Naming Conventions¶
Acronyms¶
Keep acronyms consistent in casing. Avoid "Java-style" mixed capitalization for acronyms.
Getters¶
Go prefers direct naming for getters. Do NOT prefix with Get.
Interfaces¶
Interfaces with a single method should end in -er.
2. Error Handling¶
Wrapping¶
Always wrap errors to preserve context using %w.
Checkable Errors¶
Define exported, well-known errors for conditions callers might need to check.
var (
ErrClusterNotReady = errors.New("cluster not ready")
ErrSecretNotFound = errors.New("secret not found")
)
3. Structured Logging¶
Use logr with key-value pairs. Never use fmt.Printf or log.Println.
Security Warning
NEVER log secrets, tokens, keys, or passwords. Even in debug mode.
4. Concurrency & Reconcilers¶
No Goroutines in Reconcile¶
The Reconcile loop is already concurrent (if configured). Do not spawn unmanaged goroutines.
No time.Sleep¶
Blocking a reconciler thread degrades the entire controller's performance.
5. Imports¶
Group imports into three blocks separated by newlines:
- Standard Library
- Third-party (e.g., K8s, Controller Runtime)
- Local (
github.com/dc-tec/openbao-operator/...)
import (
"context"
"fmt"
appsv1 "k8s.io/api/apps/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/dc-tec/openbao-operator/internal/config"
)
6. Constants¶
Avoid "Magic Numbers" or raw strings in logic.