config

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 14 Imported by: 3

README

Config

Common configuration

Logger

Represents a logger configuration and ability to create a slog logger instance.

type Logger struct {
    Level  string // Logger level
    Format string // logger formatter
}

Monitoring

Represents a monitoring configuration and ability to create a Sentry client and Prometheus handler.

type Monitoring struct {
	SentryDSN string // Sentry DSN
	PromAddr  string // Prometheus address for metrics
}

DB

Represents a DB connection configuration.

type DB struct {
    Host        string // required
    Port        int    // required
    User        string // required
    Password    string
    DBName      string // required
    Schema      string
    MaxIdleConn int    // default=2
    MaxOpenConn int
}

Kafka

Represents a Kafka consumer configuration.

type KafkaInput struct {
    ClientID      string // required
    Brokers       string // required
    ConsumerGroup string // required
    OffsetOldest  bool  
    Verbose       bool   // logging
}

Utility

  • GetVersion - returns the version of the application (hash commit)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetVersion added in v0.1.1

func GetVersion() string

GetVersion returns latest git hash of commit.

func InitMetrics added in v0.1.1

func InitMetrics(addr string, logger *slog.Logger)

InitMetrics init metrics handler for Prometheus.

func InitPG added in v0.2.0

func InitPG(cfg *DB) (*sqlx.DB, error)

InitPG establish DB connection.

func InitSentry added in v0.1.1

func InitSentry(dsn, ver string) error

InitSentry init Sentry client.

func InitSlog

func InitSlog(cfg *Logger, version string, hook bool) *slog.Logger

InitSlog init slog logger instance with version field and hook for Sentry.

func NewSyncProducer added in v0.3.1

func NewSyncProducer(cfg *KafkaOutput) (sarama.SyncProducer, error)

NewSyncProducer create new Sarama sync Producer.

func PrepareMessage added in v0.3.2

func PrepareMessage(topic string, message []byte) *sarama.ProducerMessage

PrepareMessage prepare Kafka message for sending.

Types

type Consumer added in v0.3.0

type Consumer struct {
	// contains filtered or unexported fields
}

Consumer represent consumer group.

func NewConsumerGroup added in v0.3.0

func NewConsumerGroup(ctx context.Context, log *slog.Logger, cfg *KafkaInput, topics string) (*Consumer, error)

NewConsumerGroup constructor for creating consumer group.

func (*Consumer) Cleanup added in v0.3.0

Cleanup is run at the end of a session, once all ConsumeClaim goroutines have exited

func (*Consumer) ConsumeClaim added in v0.3.0

func (c *Consumer) ConsumeClaim(session sarama.ConsumerGroupSession, claim sarama.ConsumerGroupClaim) error

ConsumeClaim implements ConsumerGroupHandler interface.

func (*Consumer) Message added in v0.3.0

func (c *Consumer) Message() <-chan []byte

Message representing a channel for processing messages.

func (*Consumer) Setup added in v0.3.0

Setup is run at the beginning of a new session, before ConsumeClaim

type DB added in v0.2.0

type DB struct {
	Host        string `yaml:"host" env:"HOST,required" valid:"required"`
	Port        int    `yaml:"host" env:"PORT,required" valid:"required"`
	User        string `yaml:"user" env:"USER,required" valid:"required"`
	Password    string `yaml:"password" env:"PASSWORD"`
	DBName      string `yaml:"db_name" env:"DB_NAME,required" valid:"required"`
	Schema      string `yaml:"schema" env:"SCHEMA"`
	MaxIdleConn int    `yaml:"max_idle_conn" env:"MAX_IDLE_CONN, default=2"`
	MaxOpenConn int    `yaml:"max_open_conn" env:"MAX_OPEN_CONN"`
}

DB represent struct for DB connection.

type KafkaInput added in v0.3.0

type KafkaInput struct {
	ClientID      string `yaml:"client_id" env:"CLIENT_ID,required" valid:"required"`
	Brokers       string `yaml:"brokers" env:"BROKERS,required" valid:"required"`
	ConsumerGroup string `yaml:"consumer_group" env:"CONSUMER_GROUP,required" valid:"required"`
	OffsetOldest  bool   `yaml:"offset_latest" env:"OFFSET_OLDEST"`
	Verbose       bool   `yaml:"verbose" env:"VERBOSE"`
}

KafkaInput represent consumer configuration.

type KafkaOutput added in v0.3.1

type KafkaOutput struct {
	Brokers string `yaml:"brokers" env:"BROKERS,required" valid:"required"`
}

KafkaOutput represent consumer configuration.

type Logger

type Logger struct {
	Level LoggerLevel `yaml:"level" env:"LEVEL,required" valid:"required"`
	Fmt   string      `yaml:"fmt" env:"FMT,default=json"`
}

Logger represent configuration for any logger.

type LoggerLevel

type LoggerLevel string

LoggerLevel log levels.

const (
	LoggerLevelDebug LoggerLevel = "debug"
	LoggerLevelInfo  LoggerLevel = "info"
	LoggerLevelWarn  LoggerLevel = "warn"
	LoggerLevelError LoggerLevel = "error"
)

type Monitoring added in v0.1.1

type Monitoring struct {
	SentryDSN string `yaml:"sentry_dsn" env:"SENTRY_DSN"`
	PromAddr  string `yaml:"prom_addr" env:"PROM_ADDR"`
}

Monitoring represent configuration for any monitoring.

Jump to

Keyboard shortcuts

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