Configuration Options
3 minute read
Service Configuration
WithServiceName
func WithServiceName(name string) Option
Sets the service name used in observability metadata. This includes metrics, traces, and logs. If empty, validation fails.
Default: "rivaas-app"
WithServiceVersion
func WithServiceVersion(version string) Option
Sets the service version used in observability and API documentation. Must be non-empty or validation fails.
Default: "1.0.0"
WithEnvironment
func WithEnvironment(env string) Option
Sets the environment mode. Valid values: "development", "production". Invalid values cause validation to fail. When access log scope is not set via WithAccessLogScope, production defaults to errors-only and development to full access logs.
Default: "development"
Server Configuration
WithPort
func WithPort(port int) Option
Sets the server listen port. Default is 8080 for HTTP; when using WithTLS or WithMTLS the default is 8443. Override with WithPort(n) in all cases. Can be overridden by RIVAAS_PORT when WithEnv is used.
WithServer
func WithServer(opts ...ServerOption) Option
Configures server settings. See Server Options for sub-options.
Server Transport
At most one of WithTLS or WithMTLS may be used. Configure transport at construction; Start then runs the server. Default listen port for TLS/mTLS is 8443 unless overridden by WithPort or RIVAAS_PORT.
WithTLS
func WithTLS(certFile, keyFile string) Option
Configures the server to serve HTTPS using the given certificate and key files. Both certFile and keyFile must be non-empty. Default port is 8443 unless overridden. See Server guide for examples.
WithMTLS
func WithMTLS(serverCert tls.Certificate, opts ...MTLSOption) Option
Configures the server to serve HTTPS with mutual TLS (mTLS). Requires a server certificate and typically WithClientCAs for client verification. Default port is 8443 unless overridden. See Server guide for mTLS options and examples.
Observability
WithObservability
func WithObservability(opts ...ObservabilityOption) Option
Configures all observability components (metrics, tracing, logging). See Observability Options for sub-options.
Endpoints
WithHealthEndpoints
func WithHealthEndpoints(opts ...HealthOption) Option
Enables health endpoints. See Health Options for sub-options.
WithDebugEndpoints
func WithDebugEndpoints(opts ...DebugOption) Option
Enables debug endpoints. See Debug Options for sub-options.
Middleware
WithMiddleware
func WithMiddleware(middlewares ...HandlerFunc) Option
Adds middleware during app initialization. Multiple calls accumulate.
WithoutDefaultMiddleware
func WithoutDefaultMiddleware() Option
Disables default middleware (recovery). Use when you want full control over middleware.
Router
WithRouter
func WithRouter(opts ...router.Option) Option
Passes router options to the underlying router. Multiple calls accumulate.
OpenAPI
WithOpenAPI
func WithOpenAPI(opts ...openapi.Option) Option
Enables OpenAPI specification generation. Service name and version are automatically injected from app-level configuration.
Error Formatting
WithErrorFormatter
func WithErrorFormatter(formatter errors.Formatter) Option
Configures a single error formatter for all error responses.
WithErrorFormatters
func WithErrorFormatters(formatters map[string]errors.Formatter) Option
Configures multiple error formatters with content negotiation based on Accept header.
WithDefaultErrorFormat
func WithDefaultErrorFormat(mediaType string) Option
Sets the default format when no Accept header matches. Only used with WithErrorFormatters.
Complete Example
a, err := app.New(
// Service
app.WithServiceName("orders-api"),
app.WithServiceVersion("v2.0.0"),
app.WithEnvironment("production"),
// Server
app.WithServer(
app.WithReadTimeout(10 * time.Second),
app.WithWriteTimeout(15 * time.Second),
app.WithShutdownTimeout(30 * time.Second),
),
// Observability
app.WithObservability(
app.WithLogging(logging.WithJSONHandler()),
app.WithMetrics(),
app.WithTracing(tracing.WithOTLP("localhost:4317")),
),
// Health endpoints
app.WithHealthEndpoints(
app.WithReadinessCheck("database", dbCheck),
),
// OpenAPI
app.WithOpenAPI(
openapi.WithSwaggerUI(true, "/docs"),
),
)
Next Steps
- Server Options - Server configuration reference
- Observability Options - Observability configuration reference
- API Reference - Core types and methods
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.