Why this matters
Prevents repeated work on hot paths and fails fast when configuration is invalid.
Perform one-time configuration/dependency validation at process startup (init/bootstrap). Avoid doing it inside per-request middleware/interceptor factories.
Prevents repeated work on hot paths and fails fast when configuration is invalid.
Side-by-side examples engineers can pattern-match during review.
func NewAuthInterceptor(cfg Config) grpc.UnaryServerInterceptor {
if cfg.Issuer == "" { panic("missing issuer") } // runs when wiring per-request
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { ... }
}func ValidateConfig(cfg Config) error {
if cfg.Issuer == "" { return errors.New("missing issuer") }
return nil
}
// at startup
if err := ValidateConfig(cfg); err != nil { log.Fatal(err) }
interceptor := NewAuthInterceptor(cfg)validate inside middleware factory on each wiringvalidate once at startup; construct middleware afterFrom the same buckets as this rule.