settings

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Application added in v0.16.0

type Application struct {
	Name    string `yaml:"name" env:"APPLICATION_NAME" default:"Simba Application"`
	Version string `yaml:"version" env:"APPLICATION_VERSION" default:"0.1.0"`
}

type Docs added in v0.12.0

type Docs struct {

	// GenerateOpenAPIDocs will determine if the API documentation (YAML or JSON) will be generated
	GenerateOpenAPIDocs bool `yaml:"generate-docs" env:"SIMBA_DOCS_GENERATE" default:"true"`

	// MountDocsUIEndpoint will determine if the documentation UI will be mounted
	MountDocsUIEndpoint bool `yaml:"mount-docs-endpoint" env:"SIMBA_DOCS_MOUNT_DOCS_UI_ENDPOINT" default:"true"`

	// OpenAPIFilePath is the path to the OpenAPI YAML file
	OpenAPIFilePath string `yaml:"open-api-file-path" env:"SIMBA_DOCS_OPENAPI_FILE_PATH" default:"/openapi.json"`

	// DocsUIPath is the path to the API documentation
	DocsUIPath string `yaml:"docs-path" env:"SIMBA_DOCS_UI_PATH" default:"/docs"`

	// ServiceName is the name of the service
	ServiceName string
}

type Option added in v0.14.0

type Option func(*Simba)

Option is a function that configures a Simba application settings struct.

func WithAllowUnknownFields added in v0.14.0

func WithAllowUnknownFields(allow bool) Option

WithAllowUnknownFields sets whether to allow unknown fields

func WithApplicationName added in v0.16.0

func WithApplicationName(name string) Option

WithApplicationName sets the application name

func WithApplicationVersion added in v0.16.0

func WithApplicationVersion(version string) Option

WithApplicationVersion sets the application version

func WithDocsUIPath added in v0.16.0

func WithDocsUIPath(path string) Option

WithDocsUIPath sets the docs UI path

func WithEnvGetter added in v0.16.0

func WithEnvGetter(getter func(string) string) Option

WithEnvGetter is a test-only option to mock environment variable retrieval

func WithGenerateOpenAPIDocs added in v0.16.0

func WithGenerateOpenAPIDocs(generate bool) Option

WithGenerateOpenAPIDocs sets whether to generate OpenAPI docs

func WithLogRequestBody added in v0.14.0

func WithLogRequestBody(log bool) Option

WithLogRequestBody sets whether to log request bodies

func WithLogger added in v0.14.0

func WithLogger(logger *slog.Logger) Option

WithLogger sets the logger

func WithMountDocsUIEndpoint added in v0.16.0

func WithMountDocsUIEndpoint(mount bool) Option

WithMountDocsUIEndpoint sets whether to mount the docs endpoint

func WithOpenAPIFilePath added in v0.16.0

func WithOpenAPIFilePath(path string) Option

WithOpenAPIFilePath sets the OpenAPI JSON file path

func WithRequestIdMode added in v0.16.0

func WithRequestIdMode(mode simbaModels.RequestIdMode) Option

WithRequestIdMode sets the request ID mode

func WithServerHost added in v0.14.0

func WithServerHost(host string) Option

WithServerHost sets the server host

func WithServerPort added in v0.14.0

func WithServerPort(port int) Option

WithServerPort sets the server port

type Request added in v0.8.0

type Request struct {

	// AllowUnknownFields will set the behavior for unknown fields in the Request body,
	// resulting in a 400 Bad Request response if a field is present that cannot be
	// mapped to the model struct.
	AllowUnknownFields bool `yaml:"allow-unknown-fields" env:"SIMBA_REQUEST_ALLOW_UNKNOWN_FIELDS" default:"true"`

	// LogRequestBody will determine if the Request body will be logged
	// If set to "disabled", the Request body will not be logged, which is also the default
	LogRequestBody bool `yaml:"log-request-body" env:"SIMBA_REQUEST_LOG_REQUEST_BODY" default:"false"`

	// RequestIdMode determines how the Request ID will be handled
	RequestIdMode simbaModels.RequestIdMode `yaml:"request-id-mode" env:"SIMBA_REQUEST_ID_MODE" default:"AcceptFromHeader"`
}

Request holds the Simba for the Request processing

type Server added in v0.8.0

type Server struct {

	// Host is the host the server will listen on
	Host string `yaml:"host" env:"SIMBA_SERVER_HOST" default:"0.0.0.0"`

	// Addr is the address the server will listen on
	Port int `yaml:"port" env:"SIMBA_SERVER_PORT" default:"9999"`
}

Server holds the Simba for the application server

type Simba added in v0.14.0

type Simba struct {

	// Application settings
	Application `yaml:"application"`

	// Server settings
	Server `yaml:"server"`

	// Request settings
	Request `yaml:"request"`

	// Docs settings
	Docs `yaml:"docs"`

	// Logger settings
	Logger *slog.Logger `yaml:"-" env:"-"`
	// contains filtered or unexported fields
}

Simba is a struct that holds the application settings

func Load

func Load(opts ...Option) (*Simba, error)

Load loads the application settings

func LoadWithOptions added in v0.14.0

func LoadWithOptions(opts ...Option) (*Simba, error)

LoadWithOptions loads settings using the options pattern

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL