config

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind[T any](c *T, prefix string, v *viper.Viper) *T

Bind configuration section if it implements Binder interface.

Types

type CORS

type CORS struct {
	Origins []string `mapstructure:"origins" validate:"dive,required,url"`
}

CORS is a configuration for CORS middleware.

func (*CORS) Bind

func (c *CORS) Bind(prefix string, v *viper.Viper)

Bind CORS configuration section.

func (*CORS) Validate

func (c *CORS) Validate(valid *validation.Validate) error

Validate CORS configuration section.

type Configurable

type Configurable interface {
	ServerCore() *Configuration
}

Configurable is an interface that can be implemented by extended configuration.

type Configuration

type Configuration struct {
	*config.Configuration `mapstructure:",squash"`

	// Server configuration section.
	Server *Server `mapstructure:"server"`
	// CORS configuration section.
	CORS *CORS `mapstructure:"cors"`
	// Proxy configuration section.
	Proxy *Proxy `mapstructure:"proxy"`
	// Metrics configuration section.
	Metrics *Metrics `mapstructure:"metrics"`
	// HTTPClient configuration section.
	HTTPClient *http.Configuration `mapstructure:"http_client"`
}

Configuration for the application.

func New

func New() *Configuration

New returns a new configuration.

func (*Configuration) Bind

func (c *Configuration) Bind(_ string, v *viper.Viper)

Bind binds configuration section to viper.

func (*Configuration) BindCmd

func (c *Configuration) BindCmd(cmd *cobra.Command, v *viper.Viper)

BindCmd adds configuration bindings from command arguments.

func (*Configuration) ServerCore

func (c *Configuration) ServerCore() *Configuration

ServerCore returns the web core configuration.

func (*Configuration) Validate

func (c *Configuration) Validate(validate *validation.Validate) error

Validate the configuration.

type Metrics

type Metrics struct {
	Enabled   bool     `mapstructure:"enabled"`
	Path      string   `mapstructure:"path"`
	Address   []string `mapstructure:"address" validate:"dive,required,ip_addr|cidr|eq=*"`
	SkipPaths []string `mapstructure:"skip_paths"`
}

func (*Metrics) Bind

func (c *Metrics) Bind(prefix string, v *viper.Viper)

Bind Metrics configuration section.

func (*Metrics) Validate

func (c *Metrics) Validate(valid *validation.Validate) error

Validate Metrics configuration section.

type Proxy

type Proxy struct {
	Address []string `mapstructure:"address" validate:"dive,required,ip_addr|cidr|eq=*"`
	Limit   int      `mapstructure:"limit" validate:"min=0,max=10"`
}

Proxy is a configuration for trusted proxies.

func (*Proxy) Bind

func (c *Proxy) Bind(prefix string, v *viper.Viper)

Bind Proxy configuration section.

func (*Proxy) Validate

func (c *Proxy) Validate(valid *validation.Validate) error

Validate Proxy configuration section.

type Server

type Server struct {
	HTTP  *ServerHTTP  `mapstructure:"http"`
	HTTPS *ServerHTTPS `mapstructure:"https"`
	Path  string       `mapstructure:"path"`
}

Server configuration section.

func (*Server) Bind

func (s *Server) Bind(prefix string, v *viper.Viper)

Bind server configuration section.

func (*Server) Validate

func (s *Server) Validate(valid *validation.Validate) error

Validate server configuration section.

type ServerHTTP

type ServerHTTP struct {
	Enabled bool   `mapstructure:"enabled"`
	Address string `mapstructure:"address" validate:"ip_addr|hostname|fqdn"`
	Port    int    `mapstructure:"port" validate:"required,min=1,max=65535"`
}

ServerHTTP is a HTTP server configuration.

func (*ServerHTTP) Bind

func (s *ServerHTTP) Bind(prefix string, v *viper.Viper)

Bind server configuration section.

func (*ServerHTTP) Validate

func (s *ServerHTTP) Validate(valid *validation.Validate) error

Validate server configuration section.

type ServerHTTPS

type ServerHTTPS struct {
	Enabled            bool   `mapstructure:"enabled"`
	Address            string `mapstructure:"address" validate:"ip_addr|hostname|fqdn"`
	Port               int    `mapstructure:"port" validate:"required,min=1,max=65535"`
	CertificatePEMFile string `mapstructure:"certificate_pem_file" validate:"omitempty,file"`
}

ServerHTTPS is a HTTPS server configuration.

func (*ServerHTTPS) Bind

func (s *ServerHTTPS) Bind(prefix string, v *viper.Viper)

Bind server configuration section.

func (*ServerHTTPS) Validate

func (s *ServerHTTPS) Validate(valid *validation.Validate) error

Validate server configuration section.

Jump to

Keyboard shortcuts

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