interfaces

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2024 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IAerospike added in v0.4.0

type IAerospike interface {
	// CRUD operations
	Exists(ctx context.Context, key *aerospike.Key, policy *aerospike.BasePolicy) bool
	Count(ctx context.Context, key *aerospike.Key, policy *aerospike.BasePolicy) int64
	FindOne(ctx context.Context, key *aerospike.Key, policy *aerospike.BasePolicy, bins []string) (NoSQLRow, error)
	Find(ctx context.Context, query *aerospike.Statement, policy *aerospike.QueryPolicy) (NoSQLRows, error)
	Exec(ctx context.Context, key *aerospike.Key, policy *aerospike.WritePolicy, packageName string, functionName string) (NoSQLRows, error)
	Insert(ctx context.Context, key *aerospike.Key, query interface{}, policy *aerospike.WritePolicy) (interface{}, error)
	Delete(ctx context.Context, key *aerospike.Key, policy *aerospike.WritePolicy) int64
	DeleteMany(ctx context.Context, keys []*aerospike.Key, policy *aerospike.BatchPolicy, policyDelete *aerospike.BatchDeletePolicy) int64

	// Advanced operations
	Operate(ctx context.Context, query []aerospike.BatchRecordIfc) (int64, error)

	// Access underlying database client
	GetDb() *aerospike.Client
}

type ICache

type ICache interface {
	Init(app IEngine) error
	Stop() error
	String() string

	/*
	   Has checks if the given key exists.
	   It returns true if the key exists, false otherwise.

	   Parameters:
	   - key (string): The key to check.

	   Returns:
	   - bool: true if the key exists, false otherwise.
	*/
	Has(ctx context.Context, key string) bool

	/*
	   Set sets a key with the provided data and expiration time.

	   Parameters:
	   - key: the key to set
	   - args: the data to be stored, can be of type []byte, string, or any other type that can be converted to string
	   - timeout: the duration after which the key will expire

	   Returns:
	   - error: an error if the key could not be set
	*/
	Set(ctx context.Context, key string, args any, timeout time.Duration) error

	/*
	   SetIn updates the value of a specific key within a map stored. If the key does not exist, a new map is created.
	   It takes the key, the subkey, the value to set, and the timeout duration as parameters.

	   Parameters:
	   - key: the key of the map
	   - key2: the subkey within the map to update
	   - args: the value to set
	   - timeout: the duration for which the data should be stored

	   Returns:
	   - error: an error if the operation fails, nil otherwise
	*/
	SetIn(ctx context.Context, key string, key2 string, args any, timeout time.Duration) error

	/*
	   SetMap sets a key-value pair by marshaling the input args into JSON format before calling the Set method.

	   Parameters:
	   - key: the key to set
	   - args: the value to set, will be marshaled into JSON format
	   - timeout: the duration after which the key-value pair will expire

	   Returns:
	   - error: an error if the operation encounters any issues, nil otherwise
	*/
	SetMap(ctx context.Context, key string, args any, timeout time.Duration) error

	/*
	   Get retrieves the value associated with the given key.

	   Parameters:
	   - key (string): The key to look up.

	   Returns:
	   - any: The value associated with the key.
	   - error: An error, if any occurred during the retrieval process. Returns ErrKeyNotFound if the key is not found in the cache.
	*/
	Get(ctx context.Context, key string) (any, error)

	/*
	   GetIn retrieves the value associated with the specified key and subkey.

	   Parameters:
	   - key: The key to look up.
	   - key2: The subkey to look up within the key's associated value.

	   Returns:
	   - any: The value associated with the key and subkey.
	   - error: An error if the key, subkey, or associated value is not found.

	   Notes:
	   - If the key or subkey is not found, an error with ErrKeyNotFound will be returned.
	*/
	GetIn(ctx context.Context, key string, key2 string) (any, error)

	/*
	   GetMap retrieves a value using the specified key and returns it as a map[string]interface{}.

	   Parameters:
	   - key (string): The key used to retrieve the value.

	   Returns:
	   - map[string]interface{}: The value retrieved stored as a map.
	   - error: An error if any occurred during the retrieval or unmarshalling process.
	*/
	GetMap(ctx context.Context, key string) (any, error)

	/*
	   Increment increments the value of the given key by the specified amount.
	   If the key does not exist, it sets the key with the provided value and expiration time.

	   Parameters:
	   - key: The key to increment.
	   - val: The amount by which to increment the value of the key.
	   - timeout: The duration after which the key will expire.

	   Returns:
	   - int64: New value
	   - error: An error if any occurred during the increment operation, or setting the key, or touching the key with the new expiration time.
	*/
	Increment(ctx context.Context, key string, val int64, timeout time.Duration) (int64, error)

	/*
	   IncrementIn increments the value associated with key2 in the map stored at key by the specified value val.
	   If the key does not exist, a new map is created. If an error occurs during the retrieval of the map, it is returned.
	   If the value at key2 is not an integer, an error is returned.

	   Parameters:
	   - key: The key of the map to be incremented.
	   - key2: The key within the map whose value will be incremented.
	   - val: The value by which to increment the existing value at key2.
	   - timeout: The duration after which the operation times out.

	   Returns:
	   - int64: New value
	   - error: An error if any occurred during the operation.
	*/
	IncrementIn(ctx context.Context, key string, key2 string, val int64, timeout time.Duration) (int64, error)

	/*
	   Decrement decrements the value associated with the given key by the specified amount.
	   If the key is not found in the cache, it returns ErrKeyNotFound.
	   If any other error occurs during the decrement operation, that error is returned.
	   After decrementing the value, it updates the expiration time of the key with the provided timeout.

	   Parameters:
	   - key: The key for which the value needs to be decremented.
	   - val: The amount by which the value should be decremented.
	   - timeout: The duration after which the key should expire if not accessed.

	   Returns:
	   - int64: New value
	   - error: An error if the decrement operation or updating the expiration time fails.
	*/
	Decrement(ctx context.Context, key string, val int64, timeout time.Duration) (int64, error)

	/*
	   DecrementIn decrements the value associated with key2 in the map stored at key by the specified val.
	   If the key does not exist, a new map will be created.
	   If key2 does not exist in the map, key2 will be added with the negative value of val.
	   The updated map will then be stored with the specified timeout.

	   Parameters:
	   - key: The key under which the map is stored.
	   - key2: The key within the map whose value needs to be decremented.
	   - val: The value by which key2 should be decremented.
	   - timeout: The duration after which the updated map will expire.

	   Returns:
	   - int64: New value
	   - error: An error if the operation encounters any issues, nil otherwise.
	*/
	DecrementIn(ctx context.Context, key string, key2 string, val int64, timeout time.Duration) (int64, error)

	/*
	   Delete deletes the value for a key.

	   If the key is not found in the cache, it returns ErrKeyNotFound.
	   If an error occurs during the deletion operation, that error is returned.

	   Parameters:
	   - key (string): The key for which the value needs to be deleted.

	   Returns:
	   - error: An error if the deletion operation encounters any issues.
	*/
	Delete(ctx context.Context, key string) error
	Expire(ctx context.Context, key string, timeout time.Duration) error
}

type IClient added in v0.0.9

type IClient interface {
	Init(app IEngine) error
	Stop() error
	String() string
}

type IClientBase added in v0.3.0

type IClientBase interface {
	IClient
	Fetch(ctx context.Context, method string, host string, data []byte, headers map[string][]string) chan IClientResponse
}

type IClientGrpc added in v0.3.0

type IClientGrpc interface {
	IClient
	GetClient() *grpc.ClientConn
}

type IClientResponse added in v0.0.9

type IClientResponse interface {
	GetBody() ([]byte, error)
	GetLazyBody() io.Reader
	GetHeader() map[string][]string
	Error() error
	GetRetries() int
	GetCode() int
}

type IConfig

type IConfig interface {
	Init(app IEngine) error
	Stop() error
	Has(key string) bool
	GetString(key string, def string) string
	GetBool(key string, def bool) bool
	GetInt(key string, def int) int
	GetFloat(key string, def float64) float64

	GetMapString(key string, def map[string]string) map[string]string
	GetMapBool(key string, def map[string]bool) map[string]bool
	GetMapInt(key string, def map[string]int) map[string]int
	GetMapFloat(key string, def map[string]float64) map[string]float64

	GetSliceString(key string, def []string) []string
	GetSliceBool(key string, def []bool) []bool
	GetSliceInt(key string, def []int) []int
	GetSliceFloat(key string, def []float64) []float64
}

type IController

type IController interface {
	Init(app IEngine) error
	Stop() error
	String() string
}

type ICookie added in v0.0.11

type ICookie interface {
	Set(key string, value string, path string, expires time.Duration)
	Get(key string) string
	GetAsMap() map[string]string
}

type ICtx added in v0.0.11

type ICtx interface {
	GetRequest() IRequest
	GetResponse() IResponse

	GetUserValue(key string) (interface{}, error)
	PushUserValue(key string, val interface{})

	GetRouterValue(key string) string
	SetRouteProps(values map[string]string)
}

type IDatabase

type IDatabase interface {
	Init(app IEngine) error
	Stop() error
	String() string

	Query(ctx context.Context, query string, args ...interface{}) (SQLRows, error)
	QueryRow(ctx context.Context, query string, args ...interface{}) (SQLRow, error)
	Exec(ctx context.Context, query string, args ...interface{}) error
	GetDb() interface{}
}

type IEngine added in v0.2.0

type IEngine interface {
	Init() error
	Stop() error
	GetLogger() ILogger
	GetConfig() IConfig
	SetMetrics(c IMetrics)
	SetTrace(c ITrace)
	PushCache(c ICache) IEngine
	GetCache(key string) ICache
	PushDatabase(c IDatabase) IEngine
	GetDatabase(key string) IDatabase
	PushNoSql(c INoSql) IEngine
	GetNoSql(key string) INoSql
	PushController(c IController) IEngine
	GetController(key string) IController
	PushModule(c IModules) IEngine
	GetModule(key string) IModules
	PushRepository(c IRepository) IEngine
	GetRepository(key string) IRepository
	PushService(c IService) IEngine
	GetService(key string) IService
	PushTask(c ITask) IEngine
	GetTask(key string) ITask
	RemoveTask(key string)
	RunTask(key string, args map[string]interface{}) error
	PushServer(c IServer) IEngine
	GetServer(key string) IServer
	PushClient(c IClient) IEngine
	GetClient(key string) IClient
	PushStorage(c IStorage) IEngine
	GetStorage(key string) IStorage
	PushMiddleware(c IMiddleware) IEngine
	GetMiddleware(key string) IMiddleware
}

type IHeader added in v0.0.11

type IHeader interface {
	Add(key, value string)
	Set(key string, value string)
	Get(key string) string
	Values(key string) []string
	Del(key string)
	GetAsMap() map[string][]string
}

type ILogger

type ILogger interface {
	Init(cfg IConfig) error
	Stop() error
	SetLevel(level LogLevel)
	Debug(ctx context.Context, args ...interface{})
	Info(ctx context.Context, args ...interface{})
	Warn(ctx context.Context, args ...interface{})
	Message(ctx context.Context, args ...interface{})
	Error(ctx context.Context, err error)
	Fatal(ctx context.Context, err error)
	Panic(ctx context.Context, err error)
}

type IMetrics added in v0.0.9

type IMetrics interface {
	Init(app IEngine) error
	Start() error
	Stop() error
}

type IMiddleware added in v0.0.9

type IMiddleware interface {
	Init(app IEngine) error
	Stop() error
	String() string
	Invoke(next RouteFunc) RouteFunc
}

type IModules

type IModules interface {
	Init(app IEngine) error
	Stop() error
	String() string
}

type IMongoDB added in v0.4.0

type IMongoDB interface {
	// CRUD operations
	Exists(ctx context.Context, collection string, query interface{}) bool
	Count(ctx context.Context, collection string, query interface{}, opt *options.CountOptions) int64
	FindOne(ctx context.Context, collection string, query interface{}, opt *options.FindOneOptions) (NoSQLRow, error)
	FindOneAndUpdate(ctx context.Context, collection string, query interface{}, update interface{}, opt *options.FindOneAndUpdateOptions) (NoSQLRow, error)
	Find(ctx context.Context, collection string, query interface{}, opt *options.FindOptions) (NoSQLRows, error)
	Exec(ctx context.Context, collection string, query interface{}, opt *options.AggregateOptions) (NoSQLRows, error)
	Insert(ctx context.Context, collection string, query interface{}, opt *options.InsertOneOptions) (interface{}, error)
	Update(ctx context.Context, collection string, query interface{}, update interface{}, opt *options.UpdateOptions) error
	Delete(ctx context.Context, collection string, query interface{}, opt *options.DeleteOptions) int64

	// Advanced operations
	Batch(ctx context.Context, collection string, query []mongo.WriteModel, opt *options.BulkWriteOptions) (int64, error)

	// Access underlying database
	GetDb() *mongo.Database
}

type INoSql added in v0.0.5

type INoSql interface {
	Init(app IEngine) error
	Stop() error
	String() string
}

type IQuery added in v0.0.11

type IQuery interface {
	Get(key string) string
}

type IRepository

type IRepository interface {
	Init(app IEngine) error
	Stop() error
	String() string
}

type IRequest added in v0.0.11

type IRequest interface {
	GetBody() io.ReadCloser
	GetBodySize() int64
	GetCookie() ICookie

	GetHeader() IHeader
	GetMethod() string
	GetURI() string
	GetQuery() IQuery

	GetRemoteIP() string
	GetRemoteHost() string
	GetUserAgent() string
}

type IResponse added in v0.0.11

type IResponse interface {
	Clear()
	SetBody(data []byte)
	GetBody() []byte
	SetStatus(status int)
	GetStatus() int

	Header() IHeader
	Cookie() ICookie
}

type IServer

type IServer interface {
	Init(app IEngine) error
	Start() error
	Stop() error
	String() string
}

type IServerBase added in v0.3.0

type IServerBase interface {
	IServer
	PushRoute(method string, path string, handler RouteFunc, middlewares []string)
}

type IServerGRPC added in v0.3.0

type IServerGRPC interface {
	IServer
	RegisterService(desc *grpc.ServiceDesc, impl any)
}

type IService

type IService interface {
	Init(app IEngine) error
	Stop() error
	String() string
}

type IStorage

type IStorage interface {
	Init(app IEngine) error
	Stop() error
	String() string

	Has(name string) bool
	Put(name string, data io.Reader) error
	StoreFolder(name string) error
	Read(name string) (io.ReadCloser, error)
	Delete(name string) error
	List(path string) ([]string, error)

	IsFolder(name string) (bool, error)
	GetSize(name string) (int64, error)
	GetModified(name string) (int64, error)
}

type ITask added in v0.2.0

type ITask interface {
	Init(app IEngine) error
	Stop() error
	String() string
	Start() []ITaskRunConfiguration
	Invoke(ctx context.Context, data map[string]interface{})
}

type ITaskRunConfiguration added in v0.2.0

type ITaskRunConfiguration interface {
}

type ITrace added in v0.3.0

type ITrace interface {
	Init(app IEngine) error
	Start() error
	Stop() error
}

type LogLevel

type LogLevel int
const (
	DEBUG LogLevel = iota
	INFO
	WARNING
	MESSAGE
	ERROR
	CRITICAL
)

func GetLogLevel

func GetLogLevel(str string) LogLevel

func (LogLevel) String

func (t LogLevel) String() string

type NoSQLRow added in v0.0.6

type NoSQLRow interface {
	Scan(dest any) error
}

type NoSQLRows added in v0.0.6

type NoSQLRows interface {
	Next() bool
	Scan(dest any) error
	Close() error
}

type RouteFunc added in v0.0.2

type RouteFunc func(c context.Context, ctx ICtx)

type SQLRow added in v0.0.6

type SQLRow interface {
	Scan(dest ...any) error
}

type SQLRows added in v0.0.6

type SQLRows interface {
	Next() bool
	Scan(dest ...any) error
	Close() error
}

type TaskRunAfter added in v0.2.0

type TaskRunAfter struct {
	ITaskRunConfiguration
	Restart <-chan time.Duration
	After   time.Duration
}

type TaskRunTime added in v0.2.0

type TaskRunTime struct {
	ITaskRunConfiguration
	Restart <-chan time.Time
	To      time.Time
}

Jump to

Keyboard shortcuts

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