Documentation
¶
Index ¶
- func LoadEnv(envDir string) error
- func New[T any]() (T, error)
- func NewFirestoreClient(cfg FirestoreConfig) (*firestore.Client, error)
- func NewMysqlClient(cfg MysqlConfig) (*sql.DB, error)
- func NewPostgresClient(cfg PostgresConfig) (*sqlx.DB, error)
- func NewRedisClient(cfg RedisConfig) *redis.Client
- func OtelMeterProvider(ctx context.Context, cfg OpenTelemetryConfig, r *resource.Resource) (*metric.MeterProvider, error)
- func OtelResource(ctx context.Context, cfg AppConfig, attributes ...attribute.KeyValue) (*resource.Resource, error)
- func OtelTraceProvider(ctx context.Context, cfg OpenTelemetryConfig, r *resource.Resource) (*trace.TracerProvider, error)
- func Process(envDir string, cfg interface{}) error
- type AppConfig
- type File
- type FirestoreConfig
- type MysqlConfig
- type OpenTelemetryConfig
- type PostgresConfig
- type RSAPublicKey
- type RedisConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewFirestoreClient ¶
func NewFirestoreClient(cfg FirestoreConfig) (*firestore.Client, error)
func NewMysqlClient ¶
func NewMysqlClient(cfg MysqlConfig) (*sql.DB, error)
func NewPostgresClient ¶
func NewPostgresClient(cfg PostgresConfig) (*sqlx.DB, error)
func NewRedisClient ¶
func NewRedisClient(cfg RedisConfig) *redis.Client
func OtelMeterProvider ¶
func OtelMeterProvider(ctx context.Context, cfg OpenTelemetryConfig, r *resource.Resource, ) (*metric.MeterProvider, error)
OtelMeterProvider creates and sets an otel meter provider from an otel config and resource. The purpose of this function is to standardize on the way open telemetry is configured and not have to repeat the same boilerplate code in every service or end up in a situation where every service configures open telemetry differently.
func OtelResource ¶
func OtelResource(ctx context.Context, cfg AppConfig, attributes ...attribute.KeyValue) (*resource.Resource, error)
OtelResource creates a otel resource from an app config. The purpose of this function standardize on the way open telemetry is configured and not have to repeat the same boilerplate code in every service or end up in a situation where every service configures open telemetry differently.
func OtelTraceProvider ¶
func OtelTraceProvider(ctx context.Context, cfg OpenTelemetryConfig, r *resource.Resource, ) (*trace.TracerProvider, error)
OtelTraceProvider creates and sets an otel trace provider from an otel config and resource. The purpose of this function is to standardize on the way open telemetry is configured and not have to repeat the same boilerplate code in every service or end up in a situation where every service configures open telemetry differently.
Types ¶
type File ¶
type File []byte
File is a custom envconfig decoder that reads a file from disk using the assigned environment variable as the path to the file
type FirestoreConfig ¶
type FirestoreConfig struct {
APIKey string `envconfig:"FIRESTORE_API_KEY"`
}
type MysqlConfig ¶
type MysqlConfig struct {
Password string `envconfig:"MYSQL_PASSWORD"`
User string `envconfig:"MYSQL_USER" default:"mysql"`
Port int `envconfig:"MYSQL_PORT" default:"3306"`
Database string `envconfig:"MYSQL_DB"`
Host string `envconfig:"MYSQL_HOST" default:"localhost"`
}
func (MysqlConfig) ConnectionString ¶
func (m MysqlConfig) ConnectionString() string
type OpenTelemetryConfig ¶
type OpenTelemetryConfig struct {
OpenTelemetryEndpoint string `envconfig:"OTEL_EXPORTER_OTLP_ENDPOINT" default:"localhost:4317"`
OpenTelemetryInsecure bool `envconfig:"OTEL_EXPORTER_OTLP_INSECURE" default:"true"`
OpenTelemetrySampleRate float64 `envconfig:"OTEL_TRACES_SAMPLER_ARG" default:"1.0"`
}
OpenTelemetryConfig is the configuration for the OpenTelemetry exporters. It uses the environment variables defined by the OpenTelemetry Collector but with different defaults, to make it easier to integrate into services. https://github.com/open-telemetry/opentelemetry-specification/blob/v1.20.0/specification/protocol/exporter.md
func (OpenTelemetryConfig) MetricOptions ¶
func (cfg OpenTelemetryConfig) MetricOptions() []otlpmetricgrpc.Option
func (OpenTelemetryConfig) TracerOptions ¶
func (cfg OpenTelemetryConfig) TracerOptions() []otlptracegrpc.Option
type PostgresConfig ¶
type PostgresConfig struct {
Password string `envconfig:"POSTGRES_PASSWORD"`
User string `envconfig:"POSTGRES_USER" default:"postgres"`
Port int `envconfig:"POSTGRES_PORT" default:"5432"`
Database string `envconfig:"POSTGRES_DB" default:"postgres"`
Host string `envconfig:"POSTGRES_HOST" default:"localhost"`
SSLMode string `envconfig:"POSTGRES_SSLMODE" default:"require"`
MaxConns int `envconfig:"POSTGRES_MAX_CONNS"`
MaxConnDuration time.Duration `envconfig:"POSTGRES_MAX_CONN_DURATION"`
MaxIdleConns int `envconfig:"POSTGRES_MAX_IDLE_CONNS"`
MaxIdleDuration time.Duration `envconfig:"POSTGRES_MAX_IDLE_DURATION"`
}
func (PostgresConfig) ConnectionString ¶
func (p PostgresConfig) ConnectionString() string
type RSAPublicKey ¶
RSAPublicKey is a RSA public key PEM file read from the os
func (*RSAPublicKey) Decode ¶
func (k *RSAPublicKey) Decode(value string) error
Decode a RSA public key using the environment variable value as the path to the file
type RedisConfig ¶
type RedisConfig struct {
Addr string `envconfig:"REDIS_ADDR" default:"localhost:6379"`
Password string `envconfig:"REDIS_PASSWORD"`
DB int `envconfig:"REDIS_DB"`
TLS bool `envconfig:"REDIS_TLS"`
ReadTimeout time.Duration `envconfig:"REDIS_READ_TIMEOUT" default:"1s"`
WriteTimeout time.Duration `envconfig:"REDIS_WRITE_TIMEOUT" default:"5s"`
}