vivard

package module
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: GPL-2.0 Imports: 26 Imported by: 6

README

vivard

Documentation

Index

Constants

View Source
const (
	ServiceGQL = "gql"

	ServiceSequenceProvider = "sequence"
	ServiceScripting        = "scripting"
	ServiceCRON             = "cron"
	ServiceLoggingLogrus    = "logging:logrus"
	ServiceLoggingZap       = "logging:zap"
	ServiceNATS             = "nats"
	ServiceSQL              = "sql"
	ServiceSQLX             = "sqlx"
)

well known services

View Source
const (

	//KVStringString - name for special type for Key and Value pair
	KVStringString = "_kv_string_string_"
	//KVStringStringInput - name for special input type for Key and Value pair
	KVStringStringInput = "_kv_string_string_input_"
	//KVStringInt - name for special type for Key and Value pair
	KVStringInt = "_kv_string_int_"
	//KVStringIntInput - name for special input type for Key and Value pair
	KVStringIntInput        = "_kv_string_int_input_"
	KVStringIntName         = "_kv_string_int_"
	KVStringStringName      = "_kv_string_string_"
	KVStringStringInputName = "_kv_string_string_input_" //"StringStringKVInput"
	KVStringIntInputName    = "_kv_string_int_input_"    //"StringIntKVInput"
)

Variables

View Source
var (
	// ErrValueIgnored - provider can not set config values
	ErrValueIgnored = errors.New("ignored")
	// ErrInvalidValueType - type of value is invalid
	ErrInvalidValueType = errors.New("invalid value type")
)
View Source
var (
	ErrInvalidDateFormat  = errors.New("invalid date format")
	ErrCurrentWithoutNext = errors.New("current without next")
)
View Source
var (
	//ErrNoSequenceProvider - there is not SequenceProvider registered
	ErrNoSequenceProvider = errors.New("no SequenceProvider registered")
	// ErrItemNotFound may be returned for dictionary items (wrapped with information about dictionary and id)
	ErrItemNotFound = errors.New("item not found")
)
View Source
var ContextID = &struct{ vivardName string }{"VivardContext"}

Functions

func GQLArgToMapStringInt

func GQLArgToMapStringInt(arg []interface{}) (ret map[string]int, err error)

func GQLArgToMapStringString

func GQLArgToMapStringString(arg []interface{}) (ret map[string]string, err error)

func InitZapLogger

func InitZapLogger(cfg map[string]interface{}) (*zap.Logger, error)

func NewContext

func NewContext(
	ctx context.Context,
	userID int,
	userName string,
	source string,
	roles []string,
	rolesMask int,
	ext ...interface{},
) context.Context

func Ptr

func Ptr[T any](v T) *T

func WithRequestContext added in v0.1.7

func WithRequestContext(ctx context.Context, requestContext Context) context.Context

Types

type ArrKV

type ArrKV []KVPair

func GQLArgToArrKVStringInt

func GQLArgToArrKVStringInt(arg []interface{}) (ret ArrKV, err error)

func GQLArgToArrKVStringString

func GQLArgToArrKVStringString(arg []interface{}) (ret ArrKV, err error)

func MapStringIntToArrKV

func MapStringIntToArrKV(m map[string]int) ArrKV

func MapStringStringToArrKV

func MapStringStringToArrKV(m map[string]string) ArrKV

func (ArrKV) ToMapStringInt

func (akv ArrKV) ToMapStringInt() (map[string]int, error)

func (ArrKV) ToMapStringString

func (akv ArrKV) ToMapStringString() (map[string]string, error)

type CRONService

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

CRONService provides robfig/cron functionality as a vivard service

func NewCronService

func NewCronService(ctx context.Context) *CRONService

func (*CRONService) AddFunc

func (cs *CRONService) AddFunc(spec string, cmd func(ctx context.Context) (interface{}, error)) (JobID, error)

func (*CRONService) AddNamedFunc

func (cs *CRONService) AddNamedFunc(spec string, name string, cmd func(ctx context.Context) (interface{}, error)) (JobID, error)

func (*CRONService) Cron

func (cs *CRONService) Cron() *cron.Cron

func (*CRONService) ListJobs

func (cs *CRONService) ListJobs() []*Job

func (*CRONService) Prepare

func (cs *CRONService) Prepare(eng *Engine, _ dep.Provider) (err error)

func (*CRONService) Provide

func (cs *CRONService) Provide() interface{}

func (*CRONService) SetJobContext

func (cs *CRONService) SetJobContext(ctx context.Context)

func (*CRONService) Start

func (cs *CRONService) Start(eng *Engine, _ dep.Provider) error

type ConfigProvider

type ConfigProvider interface {
	GetConfigValue(key string) interface{}
	SetConfigValue(key string, val interface{}) error
}

type Context

type Context interface {
	UserID() int
	UserType() int
	UserName() string
	Source() string
	HasRole(role string) bool
	RolesMask() int
	GetExt(key string) (interface{}, bool)
}

Context is the interface for default request context object

func RequestContext

func RequestContext(ctx context.Context) Context

type DateIterator

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

func (*DateIterator) Curr

func (di *DateIterator) Curr() (time.Time, error)

func (*DateIterator) Current

func (di *DateIterator) Current() time.Time

func (*DateIterator) Next

func (di *DateIterator) Next() bool

func (*DateIterator) SetDateStep

func (di *DateIterator) SetDateStep(y, m, d int)

func (*DateIterator) SetStep

func (di *DateIterator) SetStep(step time.Duration)

func (*DateIterator) Start

func (di *DateIterator) Start(from, to time.Time)

func (*DateIterator) StartString

func (di *DateIterator) StartString(from, to string) (err error)

type DefaultContext

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

func (DefaultContext) GetExt

func (c DefaultContext) GetExt(key string) (interface{}, bool)

func (DefaultContext) HasRole

func (c DefaultContext) HasRole(role string) bool

func (DefaultContext) Roles

func (c DefaultContext) Roles() []string

func (DefaultContext) RolesMask

func (c DefaultContext) RolesMask() int

func (DefaultContext) Source

func (c DefaultContext) Source() string

func (DefaultContext) UserID

func (c DefaultContext) UserID() int

func (DefaultContext) UserName

func (c DefaultContext) UserName() string

func (DefaultContext) UserType

func (c DefaultContext) UserType() int

type Engine

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

func NewEngine

func NewEngine() *Engine

NewEngine creates new empty Engine object

func (*Engine) ConfBool

func (eng *Engine) ConfBool(key string, def ...bool) bool

func (*Engine) ConfInt

func (eng *Engine) ConfInt(key string, def ...int) int

func (*Engine) ConfInt64

func (eng *Engine) ConfInt64(key string, def ...int64) int64

func (*Engine) ConfString

func (eng *Engine) ConfString(key string, def ...string) string

func (*Engine) ConfValue

func (eng *Engine) ConfValue(key string) interface{}

func (*Engine) Config

func (eng *Engine) Config() dep.ConfigProvider

func (*Engine) Engine

func (eng *Engine) Engine(name string) SubEngine

Engine looks for subengine with given name

func (*Engine) GetConfig

func (eng *Engine) GetConfig(name string) interface{}

GetConfig looks for config with given name and returns it

func (*Engine) GetService

func (eng *Engine) GetService(tip string) Service

GetService looks for registered service and returns it; returns nil if not found

func (*Engine) Logger

func (eng *Engine) Logger(name string) *zap.Logger

func (*Engine) RegisterConfigProvider

func (eng *Engine) RegisterConfigProvider(p ConfigProvider, priority int)

func (*Engine) SetConfValue

func (eng *Engine) SetConfValue(key string, val interface{}) error

func (*Engine) Start

func (eng *Engine) Start() error

Start performs procedure of starting the engine

func (*Engine) WithEngine

func (eng *Engine) WithEngine(se SubEngine) *Engine

WithEngine add SubEngine to list

func (*Engine) WithLogger

func (eng *Engine) WithLogger(l *zap.Logger) *Engine

WithLogger sets l as Engine's logger

func (*Engine) WithService

func (eng *Engine) WithService(name string, srv Service) *Engine

WithService add service to services list

type GQLDescriptor

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

func (*GQLDescriptor) AddInputGenerator

func (gqld *GQLDescriptor) AddInputGenerator(name string, g GQLInputTypeGenerator)

func (*GQLDescriptor) AddMutationGenerator

func (gqld *GQLDescriptor) AddMutationGenerator(name string, g GQLQueryGenerator)

func (*GQLDescriptor) AddQueryGenerator

func (gqld *GQLDescriptor) AddQueryGenerator(name string, g GQLQueryGenerator)

func (*GQLDescriptor) AddTypeGenerator

func (gqld *GQLDescriptor) AddTypeGenerator(name string, g GQLTypeGenerator)

func (*GQLDescriptor) GetInputType

func (gqld *GQLDescriptor) GetInputType(name string) graphql.Input

func (*GQLDescriptor) GetType

func (gqld *GQLDescriptor) GetType(name string) graphql.Output

type GQLEngine

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

func (*GQLEngine) CollectStatistics added in v0.1.13

func (gqe *GQLEngine) CollectStatistics(collect bool) *GQLEngine

func (*GQLEngine) Descriptor

func (gqe *GQLEngine) Descriptor() *GQLDescriptor

func (*GQLEngine) HTTPHandler

func (gqe *GQLEngine) HTTPHandler(pretty ...bool) http.HandlerFunc

func (*GQLEngine) HTTPStatisticsHandler added in v0.1.13

func (gqe *GQLEngine) HTTPStatisticsHandler(pretty ...bool) http.HandlerFunc

func (*GQLEngine) Prepare

func (gqe *GQLEngine) Prepare(_ *Engine, _ dep.Provider) error

func (*GQLEngine) Provide

func (gqe *GQLEngine) Provide() interface{}

func (*GQLEngine) SetLogger added in v0.1.13

func (gqe *GQLEngine) SetLogger(logger *zap.Logger) *GQLEngine

func (*GQLEngine) SetOptions added in v0.1.14

func (gqe *GQLEngine) SetOptions(options GQLOptions) *GQLEngine

func (*GQLEngine) Start

func (gqe *GQLEngine) Start(eng *Engine, _ dep.Provider) error

type GQLInputTypeGenerator

type GQLInputTypeGenerator func() graphql.Input

type GQLOptions added in v0.1.14

type GQLOptions struct {
	LogClientErrors          bool
	StatisticsSnapshotStep   time.Duration
	StatisticsSnapshotsCount int
}

type GQLQueryGenerator

type GQLQueryGenerator func() *graphql.Field

type GQLTypeGenerator

type GQLTypeGenerator func() graphql.Output

type Generator

type Generator func(eng *Engine) error

type Job

type Job struct {
	ID   JobID
	Name string

	Spec string

	RunCount        int
	Duration        time.Duration
	LastRunAt       time.Time
	LastRunDuration time.Duration
	LastError       error
	LastErrorTime   time.Time
	LastResult      interface{}
	// contains filtered or unexported fields
}

func (*Job) Cancel

func (j *Job) Cancel()

func (*Job) IsRunning

func (j *Job) IsRunning() bool

func (*Job) Run

func (j *Job) Run()

func (*Job) ScheduledAt

func (j *Job) ScheduledAt() *time.Time

type JobID

type JobID int

type KVPair

type KVPair struct {
	Key interface{}
	Val interface{}
}

func GQLArgToKVStringInt

func GQLArgToKVStringInt(arg map[string]interface{}) (ret KVPair, err error)

func GQLArgToKVStringString

func GQLArgToKVStringString(arg map[string]interface{}) (ret KVPair, err error)

func (KVPair) KeyInt

func (kv KVPair) KeyInt() int

func (KVPair) KeyInteger

func (kv KVPair) KeyInteger() (int, error)

func (KVPair) KeyStr

func (kv KVPair) KeyStr() string

func (KVPair) KeyString

func (kv KVPair) KeyString() (string, error)

func (KVPair) ValInt

func (kv KVPair) ValInt() int

func (KVPair) ValInteger

func (kv KVPair) ValInteger() (int, error)

func (KVPair) ValStr

func (kv KVPair) ValStr() string

func (KVPair) ValString

func (kv KVPair) ValString() (string, error)

type LoggerService

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

func NewLoggerService

func NewLoggerService(log *zap.Logger) *LoggerService

func (*LoggerService) Log

func (ls *LoggerService) Log() *zap.Logger

func (*LoggerService) Named

func (ls *LoggerService) Named(name string) *zap.Logger

func (*LoggerService) Prepare

func (ls *LoggerService) Prepare(eng *Engine, _ dep.Provider) (err error)

func (*LoggerService) Provide

func (ls *LoggerService) Provide() any

func (*LoggerService) Start

func (ls *LoggerService) Start(_ *Engine, _ dep.Provider) error

type LogrusService

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

func NewLogrusService

func NewLogrusService(log *logrus.Entry) *LogrusService

func (*LogrusService) Log

func (ls *LogrusService) Log() *logrus.Entry

func (*LogrusService) Named

func (ls *LogrusService) Named(name string) *logrus.Entry

func (*LogrusService) Prepare

func (ls *LogrusService) Prepare(eng *Engine, _ dep.Provider) (err error)

func (*LogrusService) Provide

func (ls *LogrusService) Provide() interface{}

func (*LogrusService) Start

func (ls *LogrusService) Start(eng *Engine, _ dep.Provider) error

type Sequence

type Sequence interface {
	// Next incerements current value and returns it as next value for sequence
	Next(ctx context.Context) (int, error)
	// Current returns current (last returned by Next) value
	Current(ctx context.Context) (int, error)
	// SetCurrent sets current value of Sequence to value
	SetCurrent(ctx context.Context, value int) (int, error)
}

Sequence - interface for named sequence of integer

type SequenceProvider

type SequenceProvider interface {
	// Sequence returns Sequence object for given name
	Sequence(ctx context.Context, name string) (Sequence, error)
	// ListSequences returns sequences with names containing mask (case-insensitivity may depend on implementation)
	// return map with Sequence name as key and current value as value
	ListSequences(ctx context.Context, mask string) (map[string]int, error)
}

SequenceProvider provides sequences

type Service

type Service interface {
	// Prepare will be called for each registered service before SubEngine's Prepare
	Prepare(eng *Engine, provider dep.Provider) error
	Start(eng *Engine, provider dep.Provider) error
	// Provide should return some low level object, e.g. *sql.DB for sql Service
	Provide() interface{}
}

type ServiceProvider

type ServiceProvider interface {
	ProvideServices(engine *Engine)
}

ServiceProvider may be implemented by SubEngine to register services

type SubEngine

type SubEngine interface {
	Name() string
	Prepare(engine *Engine) error
	Start() error
}

type ViperConfig

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

func NewViperConfig

func NewViperConfig() ViperConfig

func NewViperConfigForViper

func NewViperConfigForViper(v *viper.Viper) ViperConfig

func (ViperConfig) GetConfigValue

func (vc ViperConfig) GetConfigValue(key string) interface{}

func (ViperConfig) SetConfigValue

func (vc ViperConfig) SetConfigValue(key string, val interface{}) error

Directories

Path Synopsis
gen
js
vue
notification

Jump to

Keyboard shortcuts

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