Skip to main content

Go Style Guide

Decision matrix

Default coding choices

Default coding choices.
AreaExpected defaultAvoid
ErrorsWrap returned errors with %w so callers keep context and error identity.Returning opaque upstream errors with no explanation.
LoggingUse structured logr key-value logging.fmt.Printf, log.Println, or string-built log lines that lose context.
ReconcilersKeep work synchronous and requeue explicitly when you need another pass.Unmanaged goroutines or time.Sleep in reconcile code.
Imports and constantsUse 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 -er names 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,
)
Never log secrets

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 RequeueAfter when the controller should check again later.

Imports and constants

Group imports into three blocks:

  1. standard library
  2. third-party dependencies
  3. local github.com/dc-tec/openbao-operator/... packages

Name important values explicitly instead of leaving raw numbers or suffix strings in logic.

Related standards

Next release documentation

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.