configstore

package
v2.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2022 License: MIT Imports: 11 Imported by: 0

README

#common/configstore

Provides 2 backend storages (redis/postgres) and the ability to have custom ones.

Wraps everything around a cache.

Documentation

Index

Constants

View Source
const MaxRetries = 1000

Variables

View Source
var (
	ErrNotFound      = errors.New("Config not found")
	ErrInvalidConfig = errors.New("Invalid config")

	SQL    = &Postgres{}
	Cached = NewCached()
)

Functions

func HandleInvalidateCacheEvt

func HandleInvalidateCacheEvt(event *pubsub.Event)

func InitDatabases

func InitDatabases()

func InvalidateGuildCache

func InvalidateGuildCache(guildID interface{}, conf GuildConfig)

InvalidateGuildCache is a helper that both instantly invalides the local application cache As well as sending the pusub event

func KeyGuildConfig

func KeyGuildConfig(guildID int64, configName string) string

func RegisterConfig

func RegisterConfig(stor Storage, conf GuildConfig)

func StrID

func StrID(id int64) string

Types

type CachedStorage

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

func NewCached

func NewCached() *CachedStorage

func (*CachedStorage) GetGuildConfig

func (c *CachedStorage) GetGuildConfig(ctx context.Context, guildID int64, dest GuildConfig) error

func (*CachedStorage) InvalidateCache

func (c *CachedStorage) InvalidateCache(guildID int64, config string)

type GuildConfig

type GuildConfig interface {
	GetGuildID() int64
	GetUpdatedAt() time.Time
	GetName() string
}

type GuildConfigModel

type GuildConfigModel struct {
	GuildID   int64 `gorm:"primary_key"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

func (*GuildConfigModel) GetGuildID

func (gm *GuildConfigModel) GetGuildID() int64

func (*GuildConfigModel) GetUpdatedAt

func (gm *GuildConfigModel) GetUpdatedAt() time.Time

type PostFetchHandler

type PostFetchHandler interface {
	// Called after retrieving from underlying storage, before being put in cache
	// use this for any post processing etc..
	PostFetch()
}

type Postgres

type Postgres struct{}

func (*Postgres) GetGuildConfig

func (p *Postgres) GetGuildConfig(ctx context.Context, guildID int64, conf GuildConfig) error

conf is requried to be a pointer value

func (*Postgres) SetGuildConfig

func (p *Postgres) SetGuildConfig(ctx context.Context, conf GuildConfig) error

conf is requried to be a pointer value

func (*Postgres) SetIfLatest

func (p *Postgres) SetIfLatest(ctx context.Context, conf GuildConfig) (updated bool, err error)

type Storage

type Storage interface {
	// GetGuildConfig returns a GuildConfig item from db
	GetGuildConfig(ctx context.Context, guildID int64, dest GuildConfig) (err error)

	// SetGuildConfig saves the GuildConfig struct
	SetGuildConfig(ctx context.Context, conf GuildConfig) error
}

Jump to

Keyboard shortcuts

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