interfaces

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2024 License: BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ICache

type ICache interface {
	Init(app IService) 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(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(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(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(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(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(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(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(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(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(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(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(key string) error
}

type IClient added in v0.0.9

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

	Fetch(method string, host string, data []byte, headers map[string][]string) chan IClientResponse
}

type IClientResponse added in v0.0.9

type IClientResponse interface {
	GetBody() []byte
	GetHeader() map[string][]string
	Error() error
	GetRetries() int
}

type IConfig

type IConfig interface {
	Init(app IService) 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 IService) 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

	Done() <-chan struct{}
	StartTimeout(t time.Duration) context.CancelFunc

	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 IService) 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 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() error
	Stop() error
	SetLevel(level LogLevel)
	Push(level LogLevel, msg string, toParent bool)
	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Message(args ...interface{})
	Error(err error)
	Fatal(err error)
	Panic(err error)
}

type IMetrics added in v0.0.9

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

type IMiddleware added in v0.0.9

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

type IModules

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

type INoSql added in v0.0.5

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

	Count(ctx context.Context, key interface{}, query interface{}, args ...interface{}) int64
	Exists(ctx context.Context, key interface{}, query interface{}, args ...interface{}) bool
	Insert(ctx context.Context, key interface{}, query interface{}, args ...interface{}) (interface{}, error)
	FindOne(ctx context.Context, key interface{}, query interface{}, args ...interface{}) (NoSQLRow, error)
	Find(ctx context.Context, key interface{}, query interface{}, args ...interface{}) (NoSQLRows, error)
	Exec(ctx context.Context, key interface{}, query interface{}, args ...interface{}) (NoSQLRows, error)
	Update(ctx context.Context, key interface{}, query interface{}, args ...interface{}) error
	Delete(ctx context.Context, key interface{}, query interface{}, args ...interface{}) int64
	Batch(ctx context.Context, key interface{}, query interface{}, typeOp string, args ...interface{}) (int64, error)
	GetDb() interface{}
}

type IQuery added in v0.0.11

type IQuery interface {
	Get(key string) string
}

type IRepository

type IRepository interface {
	Init(app IService) 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 IService) error
	Start() error
	Stop() error
	String() string
	PushRoute(method string, path string, handler RouteFunc, middlewares []string)
}

type IService

type IService interface {
	Init() error
	Stop() error
	GetLogger() ILogger
	GetConfig() IConfig
	SetMetrics(c IMetrics)
	PushCache(c ICache) IService
	GetCache(key string) ICache
	PushDatabase(c IDatabase) IService
	GetDatabase(key string) IDatabase
	PushNoSql(c INoSql) IService
	GetNoSql(key string) INoSql
	PushController(c IController) IService
	GetController(key string) IController
	PushModule(c IModules) IService
	GetModule(key string) IModules
	PushRepository(c IRepository) IService
	GetRepository(key string) IRepository
	PushServer(c IServer) IService
	GetServer(key string) IServer
	PushClient(c IClient) IService
	GetClient(key string) IClient
	PushStorage(c IStorage) IService
	GetStorage(key string) IStorage
	PushMiddleware(c IMiddleware) IService
	GetMiddleware(key string) IMiddleware
}

type IStorage

type IStorage interface {
	Init(app IService) 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 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(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
}

Jump to

Keyboard shortcuts

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