db

package
v0.0.0-...-fa4c343 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CHANGELOG_TABLE_CONFIG = iota
	CHANGELOG_TABLE_GEOIP
)

Variables

View Source
var AutoMigrateTables = []interface{}{
	ChangeLog{},
	GlobalConfig{},
	GeoipSource{},
	GeoipCountry{},
}

Functions

This section is empty.

Types

type ChangeLog

type ChangeLog struct {
	gorm.Model
	Table int
	Key   string
}

type DBServiceGeoip

type DBServiceGeoip interface {
	DbServiceSubscriber
	GetGeoipCountries() (map[string]bool, error)
	SetGeoipCountries(countryCodes []string, allow bool) error

	GetGeoipSourceTimestamp() (time.Time, error)
	GetGeoipSource() (*GeoipSource, error)
	SetGeoipSource(timestamp time.Time, source []byte) error
}

Geoip plugin specific

type DbChangeListener

type DbChangeListener interface {
	NotifyDbChange(key string)
}

type DbService

type DbService interface {
	DbServiceSubscriber

	// NotifyChange create a ChangeLog row to notify
	// to other nodes that there is a DB change
	// in a specific table, for a specific key
	NotifyChange(table int, key string) error

	// Watch() start a go routine, that will periodically
	// check if there is any changelog
	Watch(stopChannel chan struct{})

	DbServiceConfig
	DBServiceGeoip
}

func NewDbService

func NewDbService(dbtype string, dsn string, retryAttempt uint, retryDelay time.Duration) (dbservice DbService, err error)

type DbServiceConfig

type DbServiceConfig interface {
	DbServiceSubscriber
	GetConfigs() (map[string]string, error)
	GetConfigValueForKey(key string) (string, error)
	SetConfigValueForKey(key string, value string) error
}

General WAF configuration

type DbServiceImpl

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

func (*DbServiceImpl) GetConfigValueForKey

func (ds *DbServiceImpl) GetConfigValueForKey(key string) (string, error)

func (*DbServiceImpl) GetConfigs

func (ds *DbServiceImpl) GetConfigs() (map[string]string, error)

func (*DbServiceImpl) GetGeoipCountries

func (ds *DbServiceImpl) GetGeoipCountries() (map[string]bool, error)

GetGeoipAllow returns - an enmpty list (everything is allowed/deny) - or a specifc list of country code, + allow

func (*DbServiceImpl) GetGeoipSource

func (ds *DbServiceImpl) GetGeoipSource() (*GeoipSource, error)

func (*DbServiceImpl) GetGeoipSourceTimestamp

func (ds *DbServiceImpl) GetGeoipSourceTimestamp() (time.Time, error)

func (*DbServiceImpl) NotifyChange

func (ds *DbServiceImpl) NotifyChange(table int, key string) error

func (*DbServiceImpl) SetConfigValueForKey

func (ds *DbServiceImpl) SetConfigValueForKey(key string, value string) error

func (*DbServiceImpl) SetGeoipCountries

func (ds *DbServiceImpl) SetGeoipCountries(countryCodes []string, allow bool) error

func (*DbServiceImpl) SetGeoipSource

func (ds *DbServiceImpl) SetGeoipSource(timestamp time.Time, source []byte) error

func (*DbServiceImpl) SubscribeChanges

func (ds *DbServiceImpl) SubscribeChanges(table int, listener DbChangeListener)

func (*DbServiceImpl) Watch

func (ds *DbServiceImpl) Watch(stopChannel chan struct{})

type DbServiceSubscriber

type DbServiceSubscriber interface {
	// Register to be notified when a changelog event
	// occurs on a given table
	SubscribeChanges(table int, listener DbChangeListener)
}

type GeoipCountry

type GeoipCountry struct {
	CountryCode string
	Allow       bool
}

type GeoipSource

type GeoipSource struct {
	Timestamp time.Time
	Source    []byte `gorm:"type:blob"` // Geoip2-Country.mmdb
}

GeoipSource is a one row table to store the source of the Geoip2-Country.mmdb Database are usually not good at storing large binary data, but the database is centric to the application, and I dont want to introduce a new subsystem

type GlobalConfig

type GlobalConfig struct {
	Key   string
	Value string
}

type Logger

type Logger struct {
	LogLevel                  gorm_logger.LogLevel
	SlowThreshold             time.Duration
	IgnoreRecordNotFoundError bool
}

func (*Logger) Error

func (l *Logger) Error(ctx context.Context, s string, args ...interface{})

func (*Logger) Info

func (l *Logger) Info(ctx context.Context, s string, args ...interface{})

func (*Logger) LogMode

func (l *Logger) LogMode(level gorm_logger.LogLevel) gorm_logger.Interface

func (*Logger) Trace

func (l *Logger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

func (*Logger) Warn

func (l *Logger) Warn(ctx context.Context, s string, args ...interface{})

Jump to

Keyboard shortcuts

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