config

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package config handles application and mock configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetupLog added in v0.3.0

func SetupLog(level string)

SetupLog configures the global slog logger with the given level.

Types

type CLIOverrides added in v0.13.0

type CLIOverrides struct {
	Port         int
	Addr         string
	LogLevel     string
	Verbose      bool
	ReadTimeout  string
	WriteTimeout string
	IdleTimeout  string
}

CLIOverrides holds CLI flag values that override config settings.

type Config

type Config struct {
	Server struct {
		Addr         string
		ReadTimeout  time.Duration
		WriteTimeout time.Duration
		IdleTimeout  time.Duration
	}
	Logger struct {
		Level string
	}
}

Config represents configuration of application.

func (*Config) ApplyOverrides added in v0.13.0

func (c *Config) ApplyOverrides(overrides CLIOverrides)

ApplyOverrides applies CLI flag overrides to the config.

type Endpoint

type Endpoint struct {
	Methods   []string `json:"methods,omitempty"`
	Status    int      `json:"status,omitempty"`
	Path      string   `json:"path"`
	Delay     int      `json:"delay,omitempty"`
	JSONPath  string   `json:"jsonPath,omitempty"` // path to the JSON file with endpoint
	JSON      any      `json:"json,omitempty"`
	Proxy     string   `json:"proxy,omitempty"`
	Static    string   `json:"static,omitempty"` // static file server
	Errors    *Errors  `json:"errors,omitempty"`
	AllowCors []string `json:"allowCors,omitempty"`
	Dynamic   *struct {
		Write *struct {
			JSON *struct {
				Name  string `json:"name"`  // entity name
				Key   string `json:"key"`   // path/to/a/key to store from an incoming JSON
				Value string `json:"value"` // path/to/a/value to store from an incoming JSON
			} `json:"json,omitempty"`
		} `json:"write,omitempty"`
		Read *struct {
			JSON *struct {
				Name     string `json:"name"`               // entity name
				KeyParam string `json:"keyParam,omitempty"` // key parameter name from the "path"
			} `json:"json,omitempty"`
		} `json:"read,omitempty"`
	} `json:"dynamic,omitempty"`
}

Endpoint represents API endpoint configuration.

type Errors added in v0.3.0

type Errors struct {
	Sample   float32 `json:"sample,omitempty"`
	Statuses []int   `json:"statuses,omitempty"`
}

Errors represents error simulation configuration.

type Mock

type Mock struct {
	Port         int         `json:"port,omitempty"`
	Addr         string      `json:"addr,omitempty"`
	ReadTimeout  string      `json:"readTimeout,omitempty"`
	WriteTimeout string      `json:"writeTimeout,omitempty"`
	IdleTimeout  string      `json:"idleTimeout,omitempty"`
	LogLevel     string      `json:"logLevel,omitempty"`
	Endpoints    []*Endpoint `json:"endpoints"`
}

Mock represents configuration of API.

func NewMock

func NewMock(file string) (Mock, string, error)

NewMock loads API configuration from file.

func (*Mock) ToConfig added in v0.12.0

func (m *Mock) ToConfig() Config

ToConfig converts Mock server settings into a Config with sensible defaults.

Jump to

Keyboard shortcuts

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