Documentation
¶
Index ¶
- Constants
- func AsConfigFor[T any](types ...any) any
- func LoadJSONConfig(p LoadJSONConfigParams) error
- func LoadJSONConfigInto(cfg any, automaticEnv bool, defaultCfgPath string) error
- func NewGlobalSlogLogger(p SlogLoggerParams) (*slog.Logger, error)
- func NewModule() fx.Option
- func UseSlogLogger() fx.Option
- type CoreConfig
- type CoreEnv
- func (e CoreEnv) AppAutomaticEnvValue() bool
- func (e CoreEnv) AppConfigLocationValue() (string, error)
- func (e CoreEnv) AppNameValue() string
- func (e CoreEnv) AppVersionValue() string
- func (e CoreEnv) IsProd() bool
- func (e CoreEnv) LogLevelValue() string
- func (e CoreEnv) ProfileValue() string
- func (e CoreEnv) RequiredValues() []any
- type LoadJSONConfigParams
- type SentryConfig
- type SentryEnv
- type SlogLoggerParams
Constants ¶
const ( ConfigFolder = "configs" ConfigFile = "app.json" )
const ( ProfileProduction = "production" ProfileDevelopment = "development" ProfileDebug = "debug" )
Variables ¶
This section is empty.
Functions ¶
func AsConfigFor ¶
AsConfigFor register a required struct as a required of multiple CoreConfig type, useful if you need single required object to provide multiple required type. This method allow you to inject original object, and all type it registered by this function.
func LoadJSONConfig ¶
func LoadJSONConfig(p LoadJSONConfigParams) error
LoadJSONConfig load config into CoreConfig.
func LoadJSONConfigInto ¶
LoadJSONConfigInto load json config into cfg pointer.
func NewGlobalSlogLogger ¶
func NewGlobalSlogLogger(p SlogLoggerParams) (*slog.Logger, error)
NewGlobalSlogLogger create a logger instance and register it globally.
func NewModule ¶
NewModule Create a module that autoconfigure slog, sentry and populate configuration from file or environment. The env config object must implement CoreConfig, and registered using AsConfigFor to be autopopulated. The env config must also register as SentryConfig to enable sentry feature.
func UseSlogLogger ¶
UseSlogLogger configure fx to use slog.Default logger.
Types ¶
type CoreConfig ¶
type CoreConfig interface {
// AppNameValue application name.
AppNameValue() string
// AppVersionValue application version.
AppVersionValue() string
// AppConfigLocationValue base config file to load from.
// Config file must in json format.
// Return empty string to disable loading from config file.
// Default implementations read config from file:./configs/app.json.
AppConfigLocationValue() (string, error)
// AppAutomaticEnvValue enable read env variable into config struct automatically.
AppAutomaticEnvValue() bool
// ProfileValue application env profile (production,development,debug).
ProfileValue() string
// RequiredValues the list of field that must specified.
// This method must return a list of pointer of specified field, on the same object.
RequiredValues() []any
// LogLevelValue application log level.
LogLevelValue() string
// IsProd shorthand production profile checking.
IsProd() bool
}
type CoreEnv ¶
type CoreEnv struct {
AppName string `json:"app_name" mapstructure:"app_name"`
AppVersion string `json:"app_version" mapstructure:"app_version"`
LogLevel string `json:"log_level" mapstructure:"log_level"`
Profile string `json:"profile" mapstructure:"profile"`
SentryEnv
}
nolint:staticcheck
func (CoreEnv) AppAutomaticEnvValue ¶
func (CoreEnv) AppConfigLocationValue ¶
func (CoreEnv) AppNameValue ¶
func (CoreEnv) AppVersionValue ¶
func (CoreEnv) LogLevelValue ¶
func (CoreEnv) ProfileValue ¶
func (CoreEnv) RequiredValues ¶
type LoadJSONConfigParams ¶
type LoadJSONConfigParams struct {
fx.In
Config CoreConfig
}
type SentryConfig ¶
type SentryEnv ¶
type SentryEnv struct {
SentryDsn string `json:"sentry_dsn" mapstructure:"sentry_dsn"`
SentryLogLevel string `json:"sentry_log_level" mapstructure:"sentry_log_level"`
}
func (SentryEnv) SentryDsnValue ¶
func (SentryEnv) SentryLogLevelValue ¶
type SlogLoggerParams ¶
type SlogLoggerParams struct {
fx.In
Config CoreConfig
LogConfig SentryConfig `optional:"true"`
Lifecycle fx.Lifecycle
}