plugins

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2021 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrepareLoadCsvData

func PrepareLoadCsvData(mux string, loader CsvDataLoader, args ...string)

PrepareLoadCsvData prepares loading csv data

func RegisterScheduledEvent

func RegisterScheduledEvent(evt *ScheduledEvent)

RegisterScheduledEvent register evt to engine

Types

type Cache

type Cache struct {
	Config *CacheConfig
	*cache.Cache
}

func NewCache

func NewCache(config CacheConfig) (plugin *Cache, err error)

func (*Cache) Save

func (c *Cache) Save() (err error)

type CacheConfig

type CacheConfig struct {
	ID                string        `yaml:"id" required:"true"`
	Filepath          string        `yaml:"filepath" default:""`
	AutoSave          int8          `yaml:"auto_save" default:"0"`
	CreateNewFile     bool          `yaml:"create_new_file" default:"false"`
	DefaultExpiration time.Duration `yaml:"default_expiration" default:"0s"`
	CleanupInterval   time.Duration `yaml:"cleanup_interval" default:"0s"`
}

type CsvDataLoader

type CsvDataLoader interface{} // func (interface{}, *sync.Map)

CsvDataLoader must be a type of function like: func (data *DateRecordStruct, container *sync.Map) keys of container are id or key of records values of container are pointers of DataRecordStruct

type CsvManager

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

func NewCsvManager

func NewCsvManager() (csvManager *CsvManager, err error)

func (*CsvManager) Load

func (manager *CsvManager) Load(folder string, engine Interface) (err error)

func (*CsvManager) StoreTable

func (manager *CsvManager) StoreTable(name string, mux string, container interface{})

func (*CsvManager) Table

func (manager *CsvManager) Table(name string, mux string) (*sync.Map, bool)

type EventCallback

type EventCallback func(plugins Interface, at time.Time) (err error)

EventCallback is function type of scheduled task callback

type GameLog

type GameLog struct {
	Action  string
	Fields  map[string]interface{}
	Comment string
}

type Interface

type Interface interface {
	Logger
	MasterData() MasterDataManager
	Cache(id string) *Cache
	Redis(id string) *Redis
	Mongo(id string) *Mongo
	MySQL(id string) *MySQL
	Sqlite(id string) *Sqlite
	LBClient(id string) *LBClient
}

type LBClient

type LBClient struct {
	Config *LBClientConfig
	*fasthttp.PipelineClient
}

func NewLBClient

func NewLBClient(logger Logger, config LBClientConfig) (plugin *LBClient, err error)

type LBClientConfig

type LBClientConfig struct {
	ID                  string        `yaml:"id" required:"true"`
	Scheme              string        `yaml:"scheme" default:"http"`
	Host                string        `yaml:"host" required:"true"`
	Port                uint16        `yaml:"port" required:"true"`
	MaxConns            int           `yaml:"max_conns" default:"0"`
	MaxPendingRequests  int           `yaml:"max_pending_requests" default:"0"`
	MaxBatchDelay       time.Duration `yaml:"max_batch_delay" default:"0"`
	DialDualStack       bool          `yaml:"dial_dual_stack" default:"true"`
	IsTLS               bool          `yaml:"is_tls" default:"false"`
	MaxIdleConnDuration time.Duration `yaml:"max_idle_conn_duration" default:"0"`
	ReadBufferSize      int           `yaml:"read_buffer_size" default:"0"`
	WriteBufferSize     int           `yaml:"write_buffer_size" default:"0"`
	ReadTimeout         time.Duration `yaml:"read_timeout" default:"0"`
	WriteTimeout        time.Duration `yaml:"write_timeout" default:"0"`
}

type Logger

type Logger interface {
	// Printf must have the same semantics as log.Printf
	Printf(format string, args ...interface{})
	// Infof writes info level log
	Infof(format string, args ...interface{})
	// Warnf writes warn level log
	Warnf(format string, args ...interface{})
	// Errorf writes error level log
	Errorf(format string, args ...interface{})
	// Fatalf writes error level log and panic
	Fatalf(format string, args ...interface{})
	// WithField adds a key-value pair value that will be printed out
	WithField(key string, value interface{}) *logrus.Entry
}

Logger is used for logging formatted messages

func NewLogger

func NewLogger(config LoggerConfig) (Logger, error)

type LoggerConfig

type LoggerConfig struct {
	Path     string        `yaml:"path" default:"log/"`
	InfoAge  time.Duration `yaml:"info_age" default:"72h"`
	WarnAge  time.Duration `yaml:"warn_age" default:"240h"`
	ErrorAge time.Duration `yaml:"error_age" default:"720h"`
}

LoggerConfig represents logger configuration options

type MasterDataManager

type MasterDataManager interface {
	Table(name string, mux string) (*sync.Map, bool)
	StoreTable(name string, mux string, container interface{})
}

MasterDataManager is interface that CsvManager implements

type MasterTable

type MasterTable interface {
	Record(key interface{}) (val interface{}, ok bool)
	Range(f func(key, value interface{}) bool)
}

MasterTable is interface masterDataTable implements

func MasterTableWithLogger

func MasterTableWithLogger(logger Logger, mux string, tableName string, container *sync.Map) MasterTable

type Mongo

type Mongo struct {
	Config *MongoDBConfig
	*mongo.Database
}

func NewMongo

func NewMongo(config MongoDBConfig) (plugin *Mongo, err error)

type MongoDBConfig

type MongoDBConfig struct {
	ID                      string            `yaml:"id" required:"true"`
	Hosts                   []string          `yaml:"hosts" required:"true"`
	ReplicaSet              string            `yaml:"replica_set" default:""`
	Database                string            `yaml:"database" required:"true"`
	AuthMechanism           string            `yaml:"auth_mechanism" default:""`
	AuthMechanismProperties map[string]string `yaml:"auth_mechanism_properties"`
	AuthSource              string            `yaml:"auth_source" default:""`
	Username                string            `yaml:"username" required:"true"`
	Password                string            `yaml:"password" required:"true"`
	PasswordSet             bool              `yaml:"password_set"`
	MinPoolSize             uint64            `yaml:"min_pool_size" default:"0"`
	MaxPoolSize             uint64            `yaml:"max_pool_size" default:"0"`
	MaxConnIdleTime         time.Duration     `yaml:"max_conn_idle_time" default:"0m"`
	ConnectTimeout          time.Duration     `yaml:"connect_timeout" default:"0s"`
	ServerSelectionTimeout  time.Duration     `yaml:"server_selection_timeout" default:"0s"`
	SocketTimeout           time.Duration     `yaml:"socket_timeout" default:"0s"`
	CompressionLevel        int               `yaml:"compression_level" default:"0"`

	// automatically abort transaction on errors
	AutoAbortTransaction bool `yaml:"auto_abort_transaction" default:"false"`
	// automatically commit transaction if return success
	AutoCommitTransaction bool `yaml:"auto_commit_transaction" default:"true"`
}

type MySQL

type MySQL struct {
	Config *MySQLConfig
	*gorm.DB
}

func NewMySQL

func NewMySQL(config MySQLConfig) (plugin *MySQL, err error)

type MySQLConfig

type MySQLConfig struct {
	ID              string        `yaml:"id" required:"true"`
	Addr            string        `yaml:"addr" required:"true"`
	Database        string        `yaml:"database" required:"true"`
	Username        string        `yaml:"username" required:"true"`
	Password        string        `yaml:"password" required:"true"`
	Charset         string        `yaml:"charset" default:"utf8"`
	ParseTime       string        `yaml:"parse_time" default:"True"`
	Loc             string        `yaml:"loc" default:"Local"`
	MaxIdleConns    int           `yaml:"max_idle_conns" default:"0"`
	MaxOpenConns    int           `yaml:"max_open_conns" default:"0"`
	ConnMaxIdleTime time.Duration `yaml:"conn_max_idle_time" default:"5m"`
	ConnMaxLifeTime time.Duration `yaml:"conn_max_life_time" default:"0"`

	// automatically start transaction before API be processed
	AutoWithTransaction bool `yaml:"auto_with_transaction" default:"false"`
	// automatically rollback transaction on errors
	AutoRollbackTransaction bool `yaml:"auto_rollback_transaction" default:"false"`
	// automatically commit transaction if return success
	AutoCommitTransaction bool `yaml:"auto_commit_transaction" default:"true"`
}

type Redis

type Redis struct {
	Config *RedisConfig
	redis.UniversalClient
	// contains filtered or unexported fields
}

func NewRedis

func NewRedis(config RedisConfig) (plugin *Redis, err error)

func (*Redis) Lock

func (r *Redis) Lock(key string, options ...redsync.Option) (err error)

func (*Redis) Locker

func (r *Redis) Locker() *redsync.Redsync

func (*Redis) Mutex

func (r *Redis) Mutex(name string, options ...redsync.Option) (mu *redsync.Mutex)

func (*Redis) Unlock

func (r *Redis) Unlock(key string) (status bool, err error)

type RedisConfig

type RedisConfig struct {
	ID           string        `yaml:"id" required:"true"`
	Network      string        `yaml:"network" default:"tcp"`
	Address      string        `yaml:"address" default:"localhost:6379"`
	Username     string        `yaml:"username" default:""`
	Password     string        `yaml:"password" default:""`
	DB           int           `yaml:"db" default:"0"`
	DialTimeout  time.Duration `yaml:"dial_timeout" default:"0"`
	ReadTimeout  time.Duration `yaml:"read_timeout" default:"0"`
	WriteTimeout time.Duration `yaml:"write_timeout" default:"0"`
	PoolSize     int           `yaml:"pool_size" default:"0"`
	MinIdleConns int           `yaml:"min_idle_conns" default:"0"`
	MaxConnAge   time.Duration `yaml:"max_conn_age" default:"0"`
	PoolTimeout  time.Duration `yaml:"pool_timeout" default:"0"`
	IdleTimeout  time.Duration `yaml:"idle_timeout" default:"0"`
}

type ScheduledEvent

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

ScheduledEvent is data structured of scheduled event

func NewScheduledEvent

func NewScheduledEvent(id string, interval uint16, untilAt ...*time.Time) *ScheduledEvent

NewScheduledEvent create and returns a new ScheduledEvent with given parameters

func (*ScheduledEvent) AddCallback

func (se *ScheduledEvent) AddCallback(fn EventCallback) *ScheduledEvent

AddCallback adds EventCallback to the ScheduledEvent

type Scheduler

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

Scheduler represents task Scheduler

func DefaultScheduler

func DefaultScheduler(engine Interface) (s *Scheduler)

DefaultScheduler returns an new created scheduler with default registered events

func (*Scheduler) Start

func (s *Scheduler) Start(ctx context.Context)

Start blocks until the scheduler stopped

func (*Scheduler) Stop

func (s *Scheduler) Stop()

type Sqlite

type Sqlite struct {
	Config *Sqlite3Config
	*gorm.DB
}

func NewSqlite3

func NewSqlite3(config Sqlite3Config) (plugin *Sqlite, err error)

type Sqlite3Config

type Sqlite3Config struct {
	ID       string `yaml:"id" required:"true"`
	Filename string `yaml:"filename" required:"true"`
}

Jump to

Keyboard shortcuts

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