config

package
v0.0.0-...-86597e6 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2023 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFoundAggregateTypeQueue = errors.New("Not found aggregate type queue.")
)
View Source
var (
	ErrNotFoundAggregateTypeTopic = errors.New("Not found aggregate type topic.")
)
View Source
var (
	ErrNotFoundProducer = errors.New("Not found producer")
)
View Source
var (
	ErrNotSelected = errors.New("Not selected.")
)

Functions

func AppEnv

func AppEnv() string

func IsCIorTest

func IsCIorTest() bool

func IsDev

func IsDev() bool

func IsDevOrCIorTest

func IsDevOrCIorTest() bool

func IsProduction

func IsProduction() bool

func IsStaging

func IsStaging() bool

func IsTest

func IsTest() bool

func NewExpandEnv

func NewExpandEnv(name string) (io.Reader, error)

func NewExpandEnvWithReader

func NewExpandEnvWithReader(f io.Reader) (io.Reader, error)

func Validate

func Validate(v any) error

func ValidateStruct

func ValidateStruct(v any, fields ...*validation.FieldRules) error

func WriteConfig

func WriteConfig[T TConfig](w io.Writer) error

Types

type AWS

type AWS struct {
	AccessKey string `yaml:"accessKey"`
	SecretKet string `yaml:"secretKey"`
	SNS       *SNS   `yaml:"sns"`
	SQS       *SQS   `yaml:"sqs"`
}

func (*AWS) IsSNS

func (conf *AWS) IsSNS() bool

func (*AWS) IsSQS

func (conf *AWS) IsSQS() bool

func (AWS) Validate

func (conf AWS) Validate() error

func (*AWS) WithStatic

func (conf *AWS) WithStatic() awsv2.CredentialsProvider

type App

type App struct {
	AppEnv      string `yaml:"appEnv" default:"dev"`
	TrackingEnv string `yaml:"trackingEnv" default:"dev"`
	ServiceName string `yaml:"serviceName"`
	ServiceRoot string `yaml:"serviceRoot"`
}

func (*App) SetDefaults

func (app *App) SetDefaults()

type BinlogSaver

type BinlogSaver struct {
	File *FileSaver `yaml:"file"`
}

func (*BinlogSaver) Load

func (s *BinlogSaver) Load() (string, int, error)

func (*BinlogSaver) Save

func (s *BinlogSaver) Save(file string, position int) error

func (BinlogSaver) Validate

func (s BinlogSaver) Validate() error

type Config

type Config struct {
	App       App          `yaml:"app"`
	Database  Database     `yaml:"database"`
	SSH       *SSH         `yaml:"ssh"`
	Saver     *BinlogSaver `yaml:"saver"`
	Publisher *Publisher   `yaml:"publisher"`
	Logging   Logging      `yaml:"logging"`
}

func DefaultConfig

func DefaultConfig() *Config

func LoadConfig

func LoadConfig(filePath string) (*Config, error)

func (*Config) Build

func (c *Config) Build() (string, error)

func (*Config) Connect

func (c *Config) Connect(ctx context.Context) (*sql.DB, error)

func (*Config) NewBinlogSyncer

func (c *Config) NewBinlogSyncer(serverId int) (*replication.BinlogSyncer, error)

func (Config) Validate

func (c Config) Validate() error

type Database

type Database struct {
	Host              string `yaml:"host"`
	Port              int    `yaml:"port" default:"3306"`
	Username          string `yaml:"username"`
	Password          string `yaml:"password"`
	DBName            string `yaml:"name" default:"mysql"`
	SSHTunnel         bool   `yaml:"sshTunnel"`
	TLS               *TLS   `yaml:"tls"`
	MaxOpenConn       int    `yaml:"maxOpenConn" default:"10"`
	MaxLifeTimeSecond int    `yaml:"maxLifeTimeSecond" default:"300"`
	MaxIdleConn       int    `yaml:"maxIdleConn" default:"1"`
	MaxIdleSecond     int    `yaml:"maxIdleSecond" default:"0"`
}

func (*Database) Tls

func (d *Database) Tls() *tls.Config

func (Database) Validate

func (d Database) Validate() error

type FileSaver

type FileSaver struct {
	Name string `yaml:"name"`
}

func (*FileSaver) Load

func (s *FileSaver) Load() (file string, position int, err error)

func (*FileSaver) Save

func (s *FileSaver) Save(file string, position int) error

func (FileSaver) Validate

func (s FileSaver) Validate() error

type IEndpoint

type IEndpoint struct {
	Endpoint string `yaml:"endpoint"`
}

func (IEndpoint) Validate

func (e IEndpoint) Validate() error

type Logging

type Logging struct {
	Level   slog.Level             `yaml:"level"`
	Handler logging.LoggingHandle  `yaml:"handler" default:"text"`
	Sentry  *logging.SentryConfig  `yaml:"sentry"`
	Rollbar *logging.RollbarConfig `yaml:"rollbar"`
	// contains filtered or unexported fields
}

func (Logging) Close

func (l Logging) Close()

func (*Logging) SetupLog

func (l *Logging) SetupLog()

func (Logging) Validate

func (l Logging) Validate() error

type Outbox

type Outbox struct {
	Config          `yaml:",inline"`
	*TransformTable `yaml:"outbox"`
}

func LoadOutboxConfig

func LoadOutboxConfig(filePath string) (*Outbox, error)

func (Outbox) Validate

func (conf Outbox) Validate() error

type OutboxPolling

type OutboxPolling struct {
	Config       `yaml:",inline"`
	OutboxConfig *OutboxPollingConfig `yaml:"outbox"`
}

func LoadOutboxPollingConfig

func LoadOutboxPollingConfig(filePath string) (*OutboxPolling, error)

func (OutboxPolling) Validate

func (conf OutboxPolling) Validate() error

type OutboxPollingConfig

type OutboxPollingConfig struct {
	TransformTable  `yaml:",inline"`
	ProducerName    string        `yaml:"producerName"`
	MaxRetryCount   int           `yaml:"retryCount" default:"10"`
	PollingInterval time.Duration `yaml:"pollingInterval" default:"5s"`
	RetryBackOff    time.Duration `yaml:"retryBackoff" default:"20s"`
}

func (OutboxPollingConfig) Validate

func (o OutboxPollingConfig) Validate() error

type Publisher

type Publisher struct {
	AWS *AWS `yaml:"aws"`
}

func (*Publisher) FindProducer

func (p *Publisher) FindProducer(value string) (string, error)

func (*Publisher) IsAWS

func (p *Publisher) IsAWS() bool

func (Publisher) Validate

func (p Publisher) Validate() error

type Queue

type Queue struct {
	QueueName              string       `yaml:"queueName"`
	QueueUrl               string       `yaml:"queueUrl"`
	MessageGroupIdTemplate string       `yaml:"messageGroupIdTemplate"`
	TemplateType           TemplateType `yaml:"templateType" default:"Fast"`
	Transform              Transform    `yaml:"transform"`
}

func (*Queue) GetMessageGroupId

func (t *Queue) GetMessageGroupId(mp map[string]interface{}) *string

func (*Queue) IsFIFO

func (t *Queue) IsFIFO() bool

func (Queue) Validate

func (t Queue) Validate() error

type SNS

type SNS struct {
	IEndpoint `yaml:",inline"`
	Topics    []Topic `yaml:"topics"`
	// contains filtered or unexported fields
}

func (*SNS) FindOutboxTopic

func (sns *SNS) FindOutboxTopic(aggregateType string) (Topic, error)

func (*SNS) FindOutboxTopicArn

func (sns *SNS) FindOutboxTopicArn(aggregateType string) (string, error)

func (*SNS) Validate

func (sns *SNS) Validate() error

type SQS

type SQS struct {
	IEndpoint `yaml:",inline"`
	Queues    []Queue `yaml:"queues"`
	// contains filtered or unexported fields
}

func (*SQS) FindOutboxQueue

func (sqs *SQS) FindOutboxQueue(aggregateType string) (Queue, error)

func (*SQS) FindOutboxQueueUrl

func (sqs *SQS) FindOutboxQueueUrl(aggregateType string) (string, error)

func (*SQS) Validate

func (sqs *SQS) Validate() error

type SSH

type SSH struct {
	PrivateKey        string   `yaml:"privateKey"`
	Host              string   `yaml:"host"`
	Port              int      `yaml:"port" default:"22"`
	Username          string   `yaml:"username"`
	HostKeyAlgorithms []string `yaml:"hostKeyAlgorithms" default:"[\"ssh-ed25519\"]"`
	KnownHosts        string   `yaml:"knownHosts"`
}

func (*SSH) Conn

func (conf *SSH) Conn() (*ssh.Client, error)

func (*SSH) SetDefaults

func (s *SSH) SetDefaults()

func (SSH) Validate

func (conf SSH) Validate() error

type Saver

type Saver interface {
	Save(file string, position int) error
	Load() (file string, position int, err error)
}

type TConfig

type TConfig interface {
	Config | Outbox | OutboxPolling
}

type TLS

type TLS struct {
	InsecureSkipVerify bool   `yaml:"insecureSkipVerify"`
	SeverName          string `yaml:"serverName"`
}

func (*TLS) Config

func (t *TLS) Config() *tls.Config

type TemplateType

type TemplateType string
const (
	GoTemplate   TemplateType = TemplateType("Go")
	FastTemplate TemplateType = TemplateType("Fast")
)

func (TemplateType) String

func (typ TemplateType) String() string

type Topic

type Topic struct {
	TopicArn               string       `yaml:"topicArn"`
	MessageGroupIdTemplate string       `yaml:"messageGroupIdTemplate"`
	TemplateType           TemplateType `yaml:"templateType" default:"Fast"`
	Transform              Transform    `yaml:"transform"`
}

func (*Topic) GetMessageGroupId

func (t *Topic) GetMessageGroupId(mp map[string]interface{}) *string

func (*Topic) IsFIFO

func (t *Topic) IsFIFO() bool

func (Topic) Validate

func (t Topic) Validate() error

type Trace

type Trace struct {
	Enabled  bool   `yaml:"enabled"`
	Endpoint string `yaml:"endpoint"`
}

type Transform

type Transform struct {
	Type   TransformType    `yaml:"type" default:"table"`
	Table  *TransformTable  `yaml:"table"`
	Column *TransformColumn `yaml:"column"`
	Outbox *TransformOutbox `yaml:"outbox"`
}

func (*Transform) IsOutbox

func (t *Transform) IsOutbox() bool

func (*Transform) IsTable

func (t *Transform) IsTable() bool

func (Transform) Validate

func (t Transform) Validate() error

type TransformColumn

type TransformColumn struct {
	Table      TransformTable `yaml:",inline"`
	ColumnName string         `yaml:"columnName"`
	Value      string         `yaml:"value"`
}

func (TransformColumn) Validate

func (t TransformColumn) Validate() error

type TransformOutbox

type TransformOutbox struct {
	AggregateType string `yaml:"aggregateType"`
}

func (TransformOutbox) Validate

func (t TransformOutbox) Validate() error

type TransformTable

type TransformTable struct {
	Schema    string `yaml:"schema"`
	TableName string `yaml:"tableName"`
}

func (*TransformTable) IsEnabled

func (t *TransformTable) IsEnabled(schema, tableName string) bool

func (TransformTable) Validate

func (t TransformTable) Validate() error

type TransformType

type TransformType string
const (
	TableType         TransformType = TransformType("table")
	ColumnType        TransformType = TransformType("column")
	OutboxPatternType TransformType = TransformType("outbox")
)

Jump to

Keyboard shortcuts

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