Documentation
¶
Overview ¶
Package base provides a way to initialize default resources that is used by almost all services. This package is used to load: - Context - Environment Variables - Logger - Time Resources - HTTP Client
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // DefaultHTTPClientTimeout is the default timeout for the HTTP Client. DefaultHTTPClientTimeout = 10 * time.Second // DefaultTimeLocation is the default time location. DefaultTimeLocation = "UTC" // DefaultLoggerLevel is the default logger level. DefaultLoggerLevel = zerolog.InfoLevel // DefaultLoggerOutput is the default logger output. DefaultLoggerOutput = &os.Stdout )
Functions ¶
This section is empty.
Types ¶
type Baser ¶
type Baser[envType any] interface { Ctx() context.Context CancelCtx() func() Env() envType Logger() *zerolog.Logger TimeLocation() *time.Location // TimeNow returns the current time in the time location. TimeNow() time.Time HTTPClient() *http.Client }
Baser is the interface that wraps the basic methods to get the initialized resources.
func New ¶
New initialize default resources that is used by almost all services. - Context - Environment Variables - Logger - Time Resources - HTTP Client
To load the environment variables need to pass the envType as struct with the 'env' labels like the example below.
type envModel struct {
Environment string `env:"ENVIRONMENT"`
Version string `env:"VERSION"`
Database string `env:"DATABASE"`
}
type Config ¶
type Config struct {
// If not provided, a default logger will be created with the level set to Info and output to os.Stdout.
Logger *zerolog.Logger
// If not provided, the default location will be used (UTC).
TimeLocation string
// If not provided, the default configuration will be used.
HTTPClientConfig HTTPClientConfig
}
Config is used to configure the resources that will be initialized.
type HTTPClientConfig ¶
Click to show internal directories.
Click to hide internal directories.