config

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package config contains a centralized structure for all configuration options.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterDatabaseFlags

func RegisterDatabaseFlags(v *viper.Viper, flags *pflag.FlagSet) error

RegisterDatabaseFlags registers the flags for the database configuration

func RegisterGRPCServerFlags

func RegisterGRPCServerFlags(v *viper.Viper, flags *pflag.FlagSet) error

RegisterGRPCServerFlags registers the flags for the gRPC server

func RegisterHTTPServerFlags

func RegisterHTTPServerFlags(v *viper.Viper, flags *pflag.FlagSet) error

RegisterHTTPServerFlags registers the flags for the HTTP server

func SetCryptoViperDefaults

func SetCryptoViperDefaults(v *viper.Viper)

SetCryptoViperDefaults sets the default values for the crypto configuration to be picked up by viper

func SetLoggingViperDefaults

func SetLoggingViperDefaults(v *viper.Viper)

SetLoggingViperDefaults sets the default values for the logging configuration to be picked up by viper

func SetMetricsViperDefaults

func SetMetricsViperDefaults(v *viper.Viper)

SetMetricsViperDefaults sets the default values for the metrics configuration to be picked up by viper

func SetTracingViperDefaults

func SetTracingViperDefaults(v *viper.Viper)

SetTracingViperDefaults sets the default values for the tracing configuration to be picked up by viper

func SetViperDefaults

func SetViperDefaults(v *viper.Viper)

SetViperDefaults sets the default values for the configuration to be picked up by viper

Types

type Config

type Config struct {
	HTTPServer    HTTPServerConfig `mapstructure:"http_server"`
	GRPCServer    GRPCServerConfig `mapstructure:"grpc_server"`
	LoggingConfig LoggingConfig    `mapstructure:"logging"`
	Tracing       TracingConfig    `mapstructure:"tracing"`
	Metrics       MetricsConfig    `mapstructure:"metrics"`
	Database      DatabaseConfig   `mapstructure:"database"`
	Salt          CryptoConfig     `mapstructure:"salt"`
}

Config is the top-level configuration structure.

func ReadConfigFromViper

func ReadConfigFromViper(v *viper.Viper) (*Config, error)

ReadConfigFromViper reads the configuration from the given Viper instance. This will return the already-parsed and validated configuration, or an error.

type CryptoConfig

type CryptoConfig struct {
	Memory      uint32 `mapstructure:"memory"`
	Iterations  uint32 `mapstructure:"iterations"`
	Parallelism uint   `mapstructure:"parallelism"`
	SaltLength  uint32 `mapstructure:"salt_length"`
	KeyLength   uint32 `mapstructure:"key_length"`
}

CryptoConfig is the configuration for the crypto package

func GetCryptoConfigWithDefaults

func GetCryptoConfigWithDefaults() CryptoConfig

GetCryptoConfigWithDefaults returns a CryptoConfig with default values

type DatabaseConfig

type DatabaseConfig struct {
	Host     string `mapstructure:"dbhost"`
	Port     int    `mapstructure:"dbport"`
	User     string `mapstructure:"dbuser"`
	Password string `mapstructure:"dbpass"`
	Name     string `mapstructure:"dbname"`
	SSLMode  string `mapstructure:"sslmode"`

	// If set, use credentials from the specified cloud provider.
	// Currently supported values are `aws`
	CloudProviderCredentials string `mapstructure:"cloud_provider_credentials"`

	AWSRegion string `mapstructure:"aws_region"`
	// contains filtered or unexported fields
}

DatabaseConfig is the configuration for the database

func (*DatabaseConfig) GetDBConnection

func (c *DatabaseConfig) GetDBConnection(ctx context.Context) (*sql.DB, string, error)

GetDBConnection returns a connection to the database

func (*DatabaseConfig) GetDBURI

func (c *DatabaseConfig) GetDBURI(ctx context.Context) string

GetDBURI returns the database URI

type GRPCServerConfig

type GRPCServerConfig struct {
	// Host is the host to bind to
	Host string `mapstructure:"host"`
	// Port is the port to bind to
	Port int `mapstructure:"port"`
}

GRPCServerConfig is the configuration for the gRPC server

func (*GRPCServerConfig) GetAddress

func (s *GRPCServerConfig) GetAddress() string

GetAddress returns the address to bind to

type HTTPServerConfig

type HTTPServerConfig struct {
	// Host is the host to bind to
	Host string `mapstructure:"host"`
	// Port is the port to bind to
	Port int `mapstructure:"port"`
}

HTTPServerConfig is the configuration for the HTTP server

func (*HTTPServerConfig) GetAddress

func (s *HTTPServerConfig) GetAddress() string

GetAddress returns the address to bind to

type LoggingConfig

type LoggingConfig struct {
	Level   string `mapstructure:"level"`
	Format  string `mapstructure:"format"`
	LogFile string `mapstructure:"logFile"`
}

LoggingConfig is the configuration for the logging package

type MetricsConfig

type MetricsConfig struct {
	Enabled bool `mapstructure:"enabled"`
}

MetricsConfig is the configuration for the metrics

type TracingConfig

type TracingConfig struct {
	Enabled bool `mapstructure:"enabled"`
	// for the demonstration, we use AlwaysSmaple sampler to take all spans.
	// do not use this option in production.
	SampleRatio float64 `mapstructure:"sample_ratio"`
}

TracingConfig is the configuration for our tracing capabilities

Jump to

Keyboard shortcuts

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