Documentation
¶
Overview ¶
Package common package is used to store common functions and variables
Package common package is used to store common functions and variables ¶
Package common package is used to store common functions and variables ¶
Package common package is used to store common functions and variables ¶
common/fetch.go
Package common package is used to store common functions and variables ¶
Package common package is used to store common functions and variables ¶
Package common package is used to store common functions and variables ¶
Package common package is used to store common functions and variables ¶
Package common package is used to store common functions and variables ¶
Package common package is used to store common functions and variables ¶
Package common package is used to store common functions and variables ¶
Package common package is used to store common functions and variables ¶
Package common provides common utilities and functions used across the application.
Package common provides common utilities and functions used across the application.
Index ¶
- Constants
- Variables
- func ApplyOutboundAuth(ctx context.Context, req *http.Request, cfg OutboundAuthConfig) error
- func Base64Decode(data string) (string, error)
- func Base64Encode(data string) string
- func BoolSliceToString(slice []bool, joinStr string) string
- func CalculateEntropy(data string) float64
- func CheckIPVersion(ipVal string) int
- func ConvertInfMapToStrMap(input map[interface{}]interface{}) map[string]interface{}
- func ConvertInfToMap(input interface{}) map[string]interface{}
- func ConvertInfToMapInf(input interface{}) interface{}
- func ConvertInterfaceMapToStringMap(value interface{}) interface{}
- func ConvertJSONToMap(input []byte) map[string]interface{}
- func ConvertMapIIToSI(m interface{}) interface{}
- func ConvertMapInfInf(input map[interface{}]interface{}) map[string]interface{}
- func ConvertMapToJSON(input map[string]interface{}) []byte
- func ConvertMapToString(input map[string]interface{}) string
- func ConvertSliceInfToString(input []interface{}) string
- func ConvertStringToMap(input string) map[string]interface{}
- func DebugMsg(dbgLvl DbgLevel, msg string, args ...interface{})
- func DetectLocalNetwork() (string, error)
- func FetchRemoteBytes(ctx context.Context, rawURL string, opts FetchOpts) ([]byte, string, error)
- func FetchRemoteFile(url string, timeout int, sslmode string) (string, error)
- func FetchRemoteText(ctx context.Context, rawURL string, opts FetchOpts) (string, error)
- func Float32SliceToString(slice []float32, joinStr string) string
- func Float64SliceToString(slice []float64, joinStr string) string
- func GenerateSHA256(data string) string
- func GenerateUID() string
- func GenericAPIRequest(params map[string]string) (string, error)
- func GetEngineID() string
- func GetFileExt(filePath string) string
- func GetHostIP() string
- func GetHostName() string
- func GetMicroServiceName() string
- func HostToIP(host string) []string
- func InitLogger(appName string)
- func IntSliceToString(slice []int, joinStr string) string
- func InterpolateEnvVars(input string) string
- func IsDisallowedIP(hostIP string, level int) bool
- func IsJSON(s string) bool
- func IsPathCorrect(path string) bool
- func IsURLValid(url string) bool
- func JSONStrToMap(s string) (map[string]interface{}, error)
- func JsonParser(doc map[string]interface{}, keys ...string) interface{}
- func KVSErrorIsKeyNotFound(err error) bool
- func MapStrToJSONStr(m map[string]string) (string, error)
- func MapToJSONStr(m map[string]interface{}) (string, error)
- func NewAuthenticatedClient(ctx context.Context, audience string) (*http.Client, error)
- func NormalizeURL(url string) string
- func PrepareSlice(slice *[]string, flags uint32) []string
- func RegisterAPIPluginRoute(path string, methods []string, description string, consoleOnly bool, ...)
- func RegisterAPIRoute(path string, methods []string, description string, consoleOnly bool, ...)
- func ResolveDNS(host string) (string, error)
- func SafeEscapeJSONString(s any) string
- func SafeJSON(v any) string
- func SafeTransport(timeout int, sslmode string) *http.Transport
- func SanitizeJSON(input string) string
- func SetDebugLevel(dbgLvl DbgLevel)
- func SetDebugLevelFromString(dbgLvlStr string)
- func SetLoggerPrefix(prefix string)
- func SliceContains(slice []string, item string) bool
- func StringToFloat(s string) float64
- func StringToFloat32(s string) float32
- func StringToInt(s string) int
- func URLToHost(url string) string
- func UpdateLoggerConfig(logType string)
- type APIResponse
- type APIRoute
- type CounterInfo
- type CounterLease
- type CounterValue
- type CounterWindow
- type CustomTime
- type DbgLevel
- type DbgLogType
- type Entry
- type EnvValue
- type FetchOpts
- type FlexibleDate
- type KeyValueStore
- func (kv *KeyValueStore) AllKeys() []string
- func (kv *KeyValueStore) AllKeysAndCIDs() []string
- func (kv *KeyValueStore) CleanSession(ctxID string)
- func (kv *KeyValueStore) CreateCounter(key string, counterValue CounterValue, source string) bool
- func (kv *KeyValueStore) CreateCounterBase(key string, maxVal int64, source string) error
- func (kv *KeyValueStore) Decrement(key, ctxID string, step int64) (int64, error)
- func (kv *KeyValueStore) Delete(key string, ctxID string, flags ...bool) error
- func (kv *KeyValueStore) DeleteAll()
- func (kv *KeyValueStore) DeleteAllByCID(ctxID string)
- func (kv *KeyValueStore) DeleteByCID(ctxID string, flags ...bool)
- func (kv *KeyValueStore) DeleteNonPersistent()
- func (kv *KeyValueStore) DeleteNonPersistentByCID(ctxID string)
- func (kv *KeyValueStore) Get(key string, ctxID string) (any, Properties, error)
- func (kv *KeyValueStore) GetBySource(key string, source string) (interface{}, Properties, error)
- func (kv *KeyValueStore) GetCounterInfo(key string) (*CounterInfo, error)
- func (kv *KeyValueStore) GetWithCtx(key string, source string, ctxID string) (interface{}, Properties, error)
- func (kv *KeyValueStore) Increment(key, ctxID string, step int64) (int64, error)
- func (kv *KeyValueStore) Keys(ctxID string) []string
- func (kv *KeyValueStore) Release(key string, leaseID string) error
- func (kv *KeyValueStore) Set(key string, value interface{}, properties Properties) error
- func (kv *KeyValueStore) SetSharedCallback(callback SharedCallback)
- func (kv *KeyValueStore) Size() int
- func (kv *KeyValueStore) ToJSON() string
- func (kv *KeyValueStore) TryAcquire(key string, slots int64, ttl time.Duration, owner string) (string, bool, error)
- func (kv *KeyValueStore) WithCounter(key string, fn func(entry *Entry, cv *CounterValue) error) error
- type LoggerCfg
- type OpenAPIComponents
- type OpenAPIContent
- type OpenAPIInfo
- type OpenAPIOperation
- type OpenAPIOptions
- type OpenAPIParameter
- type OpenAPIPath
- type OpenAPIRequestBody
- type OpenAPIResponse
- type OpenAPISchema
- type OpenAPIServer
- type OpenAPISpec
- type OutboundAuthConfig
- type Properties
- type SafeMutex
- type SharedCallback
- type StdAPIError
- type StdAPIQuery
- type StdAPISuccess
- type UserAgent
- type UserAgentGroup
- type UserAgentsDB
- func (uaDB *UserAgentsDB) GetAgentByTypeAndOS(uaType, os string) string
- func (uaDB *UserAgentsDB) GetAgentByTypeAndOSAndBRG(uaType, os, brg string) string
- func (uaDB *UserAgentsDB) GetAgentByTypeAndOSAndBRGAndPCT(uaType, os, brg string, pct float64) string
- func (uaDB *UserAgentsDB) GetAnyUserAgent() string
- func (uaDB *UserAgentsDB) InitUserAgentsDB() error
- func (uaDB *UserAgentsDB) IsEmpty() bool
Constants ¶
const ( // EnableStr is a constant for the string "enable". EnableStr = "enable" // DisableStr is a constant for the string "disable". DisableStr = "disable" // LoalhostStr is a constant for the string "localhost". LoalhostStr = "localhost" // LocalStr is a constant for the string "local". LocalStr = "local" // NowhereStr is a constant for the string "nowhere". NowhereStr = "nowhere" // AlwaysStr is a constant for the string "always". AlwaysStr = "always" // ClickStr is a constant for the string "click". ClickStr = "click" // LClickStr is a constant for the string "left_click". LClickStr = "left_click" // RClickStr is a constant for the string "right_click". RClickStr = "right_click" // HTTPStr is a constant for the string "http". HTTPStr = "http" // HTTPSStr is a constant for the string "https". HTTPSStr = "https" )
const ( // ActionKVSCSet Set action ActionKVSCSet = "set" // ActionKVSCUpdate Update action ActionKVSCUpdate = "update" // ActionKVSCDelete Delete action ActionKVSCDelete = "delete" // ErrKVKeyNotFound is the generic message for key not found errors ErrKVKeyNotFound = "key not found in key-value store" )
const ( // DbgLogTypeStdout is the standard output DbgLogTypeStdout = 0 // DbgLogTypeFile is the file output DbgLogTypeFile = 1 // DbgLogTypeSyslog is the syslog output DbgLogTypeSyslog = 2 )
const ( // DbgLvlDebug5 is the debug level DbgLvlDebug5 = 5 // DbgLvlDebug4 is the debug level DbgLvlDebug4 = 4 // DbgLvlDebug3 is the debug level DbgLvlDebug3 = 3 // DbgLvlDebug2 is the debug level DbgLvlDebug2 = 2 // DbgLvlDebug1 is the debug level DbgLvlDebug1 = 1 // DbgLvlDebug is the debug level DbgLvlDebug = 1 // DbgLvlInfo is the info debug level DbgLvlInfo = 0 // DbgLvlWarn is the warning debug level DbgLvlWarn = -1 // DbgLvlError is the error debug level DbgLvlError = -2 // DbgLvlFatal is the fatal debug level (this will also exit the program!) DbgLvlFatal = -3 )
const ( // DefaultFilePerms is the default file permissions DefaultFilePerms = 0644 // DefaultDirPerms is the default directory permissions DefaultDirPerms = 0755 )
Variables ¶
var ( // UsrAgentStrMap is a list of valid user agent strings. UsrAgentStrMap = map[string]string{ "chrome-desktop01": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.6367.78 Safari/537.36", "chrome-mobile01": "Mozilla/5.0 (Linux; Android 10; SM-G960F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.112 Mobile Safari/537.36", "firefox-desktop01": "Mozilla/5.0 (X11; Linux x86_64; rv:85.0) Gecko/20100101 Firefox/85.0", "firefox-mobile01": "Mozilla/5.0 (Android 10; Mobile; rv:85.0) Gecko/20100101 Firefox/85.0", "chromium-desktop01": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.112 Safari/537.36", "chromium-mobile01": "Mozilla/5.0 (Linux; Android 10; SM-G960F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.112 Mobile Safari/537.36", } )
Functions ¶
func ApplyOutboundAuth ¶ added in v1.2.0
func Base64Decode ¶ added in v0.9.5
Base64Decode decodes a base64 string to a normal string.
func Base64Encode ¶ added in v0.9.4
Base64Encode encodes a string to base64, this may be required by some configurations.
func BoolSliceToString ¶ added in v0.9.5
BoolSliceToString converts a slice of bool to a string.
func CalculateEntropy ¶ added in v0.9.5
CalculateEntropy of a string
func CheckIPVersion ¶ added in v0.9.2
CheckIPVersion checks the IP version of the given IP address
func ConvertInfMapToStrMap ¶ added in v0.9.5
func ConvertInfMapToStrMap(input map[interface{}]interface{}) map[string]interface{}
ConvertInfMapToStrMap converts a map[interface{}]interface{} to a map[string]interface{}
func ConvertInfToMap ¶ added in v0.9.5
func ConvertInfToMap(input interface{}) map[string]interface{}
ConvertInfToMap converts interface{} values to map[string]interface{}, handling both map[string]interface{} and map[interface{}]interface{} cases recursively.
func ConvertInfToMapInf ¶ added in v0.9.5
func ConvertInfToMapInf(input interface{}) interface{}
ConvertInfToMapInf converts an interface{} to a map[string]interface{} and recursively converts nested maps as an interface{}
func ConvertInterfaceMapToStringMap ¶
func ConvertInterfaceMapToStringMap(value interface{}) interface{}
ConvertInterfaceMapToStringMap recursively converts map[interface{}]interface{} to map[string]interface{}.
func ConvertJSONToMap ¶ added in v0.9.5
ConvertJSONToMap converts a JSON document to a map[string]interface{}
func ConvertMapIIToSI ¶ added in v0.9.5
func ConvertMapIIToSI(m interface{}) interface{}
ConvertMap converts a map[interface{}]interface{} to a map[string]interface{}
func ConvertMapInfInf ¶ added in v0.9.5
func ConvertMapInfInf(input map[interface{}]interface{}) map[string]interface{}
ConvertMapInfInf recursively converts a map[interface{}]interface{} to map[string]interface{}
func ConvertMapToJSON ¶ added in v0.9.5
ConvertMapToJSON converts a map[string]interface{} to a JSON document
func ConvertMapToString ¶ added in v0.9.5
ConvertMapToString converts a map[string]interface{} to a string
func ConvertSliceInfToString ¶ added in v0.9.5
func ConvertSliceInfToString(input []interface{}) string
ConvertSliceInfToString converts a slice of interfaces into a string
func ConvertStringToMap ¶ added in v0.9.5
ConvertStringToMap converts a string to a map[string]interface{}
func DetectLocalNetwork ¶ added in v0.9.5
DetectLocalNetwork finds the local network the machine is connected to
func FetchRemoteBytes ¶ added in v0.9.7
FetchRemoteBytes fetches raw bytes from HTTP(S) and optionally s3:// (when built with aws_s3 tag).
func FetchRemoteFile ¶ added in v0.9.2
FetchRemoteFile fetches a remote file and returns the contents as a string.
func FetchRemoteText ¶ added in v0.9.7
FetchRemoteText is a convenience wrapper that enforces text-like MIME and returns string.
func Float32SliceToString ¶ added in v0.9.5
Float32SliceToString converts a slice of float32 to a string.
func Float64SliceToString ¶ added in v0.9.5
Float64SliceToString converts a slice of float64 to a string.
func GenerateSHA256 ¶ added in v0.9.5
GenerateSHA256 generates a SHA256 hash of the input string.
func GenerateUID ¶ added in v0.9.5
func GenerateUID() string
GenerateUID generates a unique identifier using Google's UID format and package
func GenericAPIRequest ¶ added in v0.9.5
GenericAPIRequest is a generic API request. (it uses passed params to determine the request) url = API URL method = HTTP method (GET, POST, etc.) headers = HTTP headers body = HTTP request body auth = HTTP request authentication
func GetFileExt ¶
GetFileExt returns a file extension (if any)
func GetHostName ¶ added in v0.9.5
func GetHostName() string
GetHostName returns the hostname of the machine
func GetMicroServiceName ¶ added in v0.9.5
func GetMicroServiceName() string
GetMicroServiceName returns the microservice name from the environment variable
func IntSliceToString ¶ added in v0.9.5
IntSliceToString converts a slice of integers to a string.
func InterpolateEnvVars ¶
InterpolateEnvVars replaces occurrences of `${VAR}` or `$VAR` in the input string with the value of the VAR environment variable.
func InterpolateEnvVars(input string) string {
envVarPattern := regexp.MustCompile(`\$\{?(\w+)\}?`)
return envVarPattern.ReplaceAllStringFunc(input, func(varName string) string {
// Trim ${ and } from varName
trimmedVarName := varName
trimmedVarName = strings.TrimPrefix(trimmedVarName, "${")
trimmedVarName = strings.TrimSuffix(trimmedVarName, "}")
// Return the environment variable value
return os.Getenv(trimmedVarName)
})
}
func IsDisallowedIP ¶
IsDisallowedIP parses the ip to determine if we should allow the HTTP client to continue
func IsPathCorrect ¶
IsPathCorrect checks if the given path exists
func IsURLValid ¶ added in v0.9.5
IsURLValid checks if a URL is valid.
func JSONStrToMap ¶ added in v0.9.4
JSONStrToMap converts a JSON string to a map
func JsonParser ¶ added in v0.9.5
JsonParser recursively traverses the JSON document (represented as map[string]interface{}) following the sequence of keys provided.
func KVSErrorIsKeyNotFound ¶ added in v1.0.7
KVSErrorIsKeyNotFound checks if the given error indicates that a key was not found in the key-value store.
func MapStrToJSONStr ¶ added in v0.9.5
MapStrToJSONStr converts a map[string]string to a JSON string
func MapToJSONStr ¶ added in v0.9.5
MapToJSONStr converts a map to a JSON string
func NewAuthenticatedClient ¶ added in v1.2.0
func NormalizeURL ¶ added in v0.9.5
NormalizeURL normalizes a URL by trimming trailing slashes and converting it to lowercase.
func PrepareSlice ¶ added in v0.9.3
PrepareSlice trims spaces from all elements of a slice. PrepareSlice prepares a slice of strings by trimming and lowercasing each element.
func RegisterAPIPluginRoute ¶ added in v1.2.0
func RegisterAPIPluginRoute( path string, methods []string, description string, consoleOnly bool, successStatus int, querySchemaJSON string, requestSchemaJSON string, responseSchemaJSON string, )
RegisterAPIPluginRoute is a helper function to register an API route for a plugin, which includes additional metadata for the plugin's API. The hasBody and hasQuery parameters can be used to specify the expected structure of the request body and query parameters, respectively, which can be used for generating OpenAPI documentation and validating incoming requests.
func RegisterAPIRoute ¶ added in v1.2.0
func RegisterAPIRoute( path string, methods []string, description string, consoleOnly bool, plugin bool, successStatus int, hasBody any, hasQuery any, hasResponse any, )
RegisterAPIRoute registers a new API route with the given parameters.
func ResolveDNS ¶ added in v1.1.20
ResolveDNS resolves the fully qualified domain name (FQDN) of a given host into its corresponding IP address.
func SafeEscapeJSONString ¶ added in v0.9.5
SafeEscapeJSONString escapes a string for JSON and for embedding in quoted contexts
func SafeJSON ¶ added in v1.1.22
Utility function to safely convert any value to a JSON string, returning a placeholder if it fails (it helps avoiding walking maps that might be too deep or contain cycles, or being changed dynamically while being marshaled)
func SafeTransport ¶
SafeTransport creates a safe HTTP transport
func SanitizeJSON ¶ added in v0.9.8
SanitizeJSON tries to fix common JSON issues like unescaped quotes, duplicate commas, trailing commas
func SetDebugLevel ¶
func SetDebugLevel(dbgLvl DbgLevel)
SetDebugLevel allows to set the current debug level
func SetDebugLevelFromString ¶ added in v0.9.5
func SetDebugLevelFromString(dbgLvlStr string)
SetDebugLevelFromString sets the debug level based on a string input
func SetLoggerPrefix ¶ added in v0.9.2
func SetLoggerPrefix(prefix string)
SetLoggerPrefix sets the logger prefix
func SliceContains ¶ added in v0.9.3
SliceContains checks if a slice contains a specific item.
func StringToFloat ¶ added in v0.9.4
StringToFloat converts a string to a float
func StringToFloat32 ¶ added in v0.9.4
StringToFloat32 converts String to FLoat32
func StringToInt ¶ added in v0.9.3
StringToInt converts a string to an integer
func UpdateLoggerConfig ¶
func UpdateLoggerConfig(logType string)
UpdateLoggerConfig Updates the logger configuration
Types ¶
type APIResponse ¶ added in v0.9.5
type APIResponse struct {
StatusCode int `json:"status_code" yaml:"status_code"`
Body string `json:"body" yaml:"body"`
}
APIResponse is a generic API response.
type APIRoute ¶ added in v1.2.0
type APIRoute struct {
Path string `json:"path"`
Methods []string `json:"methods"`
Description string `json:"description"`
RequiresQ bool `json:"requires_q"`
ConsoleOnly bool `json:"console_only"`
Plugin bool `json:"plugin"`
SuccessStatus int `json:"success_status,omitempty"` // optional, e.g. 200, 201, etc.
BodyType any `json:"body_type,omitempty"` // optional, can be used to generate OpenAPI schema for request body
BodySchemaRef string `json:"body_schema_ref,omitempty"` // url to schema in components, optional
QueryType any `json:"query_type,omitempty"` // optional, can be used to generate OpenAPI schema for query parameters
QuerySchemaRef string `json:"query_schema_ref,omitempty"` // url to schema in components, optional
ResponseType any `json:"response_type,omitempty"`
ResponseSchemaRef string `json:"response_schema_ref,omitempty"` // url to schema in components, optional
}
APIRoute represents the structure of an API route, including its path, supported methods, description, and other metadata.
func GetAPIRoutes ¶ added in v1.2.0
func GetAPIRoutes() []APIRoute
GetAPIRoutes returns the list of registered API routes.
type CounterInfo ¶ added in v1.0.7
type CounterInfo struct {
Max int64 `json:"max"`
Current int64 `json:"current"`
Available int64 `json:"available"`
Leases int `json:"leases"`
Version uint64 `json:"version"`
}
CounterInfo provides a summary of the counter's state.
type CounterLease ¶ added in v1.0.7
type CounterLease struct {
// Number of slots acquired
Slots int64 `json:"slots"`
// Owner identity (engine ID, worker ID, etc.)
Owner string `json:"owner"`
// When the lease was acquired
AcquiredAt time.Time `json:"acquired_at"`
// Lease expiration
ExpiresAt time.Time `json:"expires_at"`
}
CounterLease represents a lease on a counter.
type CounterValue ¶ added in v1.0.7
type CounterValue struct {
// Hard limit
Max int64 `json:"max"`
// Current total acquired slots
Current int64 `json:"current"`
// Active leases by ID
Leases map[string]CounterLease `json:"leases"`
// Monotonic version for reconciliation
Version uint64 `json:"version"`
// Optional, for future RPS windowing
Window *CounterWindow `json:"window,omitempty"`
}
CounterValue represents a counter with leasing capabilities.
type CounterWindow ¶ added in v1.0.7
type CounterWindow struct {
WindowSize time.Duration `json:"window_size"`
WindowStart time.Time `json:"window_start"`
Count int64 `json:"count"`
}
CounterWindow represents a time window for "rate limiting" or other similar purposes.
type CustomTime ¶ added in v1.2.0
CustomTime wraps time.Time to provide custom parsing.
func (*CustomTime) IsEmpty ¶ added in v1.2.0
func (ct *CustomTime) IsEmpty() bool
IsEmpty checks if the CustomTime is empty.
func (*CustomTime) UnmarshalYAML ¶ added in v1.2.0
func (ct *CustomTime) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML parses date strings from the YAML file.
type DbgLevel ¶
type DbgLevel int
DbgLevel is an enum to represent the debug level type
func GetDebugLevel ¶
func GetDebugLevel() DbgLevel
GetDebugLevel returns the value of the current debug level
type Entry ¶ added in v0.9.5
type Entry struct {
Value any
Properties Properties
}
Entry represents a key-value pair along with its properties.
type EnvValue ¶ added in v0.9.5
type EnvValue struct {
// Name is the name of the environment variable
Name string
// Value is the value of the environment variable
Value interface{}
// Type is the type of the environment variable
Type string
}
EnvValue is a struct to represent an environment variable
func ProcessEnvTemplate ¶ added in v0.9.5
ProcessEnvTemplate processes an environment variable template
type FetchOpts ¶ added in v0.9.7
type FetchOpts struct {
Timeout time.Duration // total request timeout (incl. redirects)
ConnectTimeout time.Duration // TCP connect timeout
SSLMode string // your SafeTransport knob
MaxSize int64 // hard cap for body (e.g., 8<<20)
AllowedMIMEs []string // allowlist of MIME types (prefix match OK, e.g. "text/", "application/json")
Headers map[string]string // extra headers
SSRFGuard string // "", "on", or "strict"
UserAgent string // default if empty: "theCROWler/1.0"
Retries int // retry count for transient network/5xx/429
RetryBaseDelay time.Duration // base backoff, e.g. 200ms
FollowRedirects bool // default true
MaxRedirects int // default 5
DropAuthOnRedirect bool // default true
}
FetchOpts holds knobs for robust fetching.
type FlexibleDate ¶ added in v0.9.3
FlexibleDate is a type that can be used to parse dates in different formats
func (FlexibleDate) MarshalJSON ¶ added in v0.9.3
func (fd FlexibleDate) MarshalJSON() ([]byte, error)
MarshalJSON returns a date as a JSON string
func (FlexibleDate) String ¶ added in v0.9.3
func (fd FlexibleDate) String() string
String returns a date as a string
func (FlexibleDate) Time ¶ added in v0.9.3
func (fd FlexibleDate) Time() time.Time
Time returns a date as a time.Time
func (*FlexibleDate) UnmarshalJSON ¶ added in v0.9.3
func (fd *FlexibleDate) UnmarshalJSON(b []byte) error
UnmarshalJSON parses a date from a JSON string
type KeyValueStore ¶ added in v0.9.5
type KeyValueStore struct {
// contains filtered or unexported fields
}
KeyValueStore stores key-value pairs with properties and ensures thread safety.
var (
KVStore *KeyValueStore
)
KVStore is the global key-value store
func NewKeyValueStore ¶ added in v0.9.5
func NewKeyValueStore() *KeyValueStore
NewKeyValueStore initializes the key-value store.
func (*KeyValueStore) AllKeys ¶ added in v0.9.5
func (kv *KeyValueStore) AllKeys() []string
AllKeys returns a slice of all keys (without the CIDs) in the store (ignoring context).
func (*KeyValueStore) AllKeysAndCIDs ¶ added in v0.9.5
func (kv *KeyValueStore) AllKeysAndCIDs() []string
AllKeysAndCIDs returns a slice of all keys in the store (ignoring context).
func (*KeyValueStore) CleanSession ¶ added in v0.9.5
func (kv *KeyValueStore) CleanSession(ctxID string)
CleanSession clears all key-value pairs that are session valid for the given CID.
func (*KeyValueStore) CreateCounter ¶ added in v1.0.7
func (kv *KeyValueStore) CreateCounter( key string, counterValue CounterValue, source string, ) bool
CreateCounter creates a new counter in the key-value store. It returns true if the counter was created, false if it already exists.
func (*KeyValueStore) CreateCounterBase ¶ added in v1.0.7
func (kv *KeyValueStore) CreateCounterBase( key string, maxVal int64, source string, ) error
CreateCounterBase creates a new counter in the key-value store.
func (*KeyValueStore) Decrement ¶ added in v0.9.5
func (kv *KeyValueStore) Decrement(key, ctxID string, step int64) (int64, error)
Decrement decrements the value for a given key and context by a specified step and it's thread safe.
func (*KeyValueStore) Delete ¶ added in v0.9.5
func (kv *KeyValueStore) Delete(key string, ctxID string, flags ...bool) error
Delete removes a key-value pair by key and context. Flags can be used to specify whether to delete persistent. If no flags are provided, only non-persistent entries are deleted. Flag[0] set is to delete persistent entries
func (*KeyValueStore) DeleteAll ¶ added in v0.9.5
func (kv *KeyValueStore) DeleteAll()
DeleteAll clears all key-value pairs from the store.
func (*KeyValueStore) DeleteAllByCID ¶ added in v0.9.5
func (kv *KeyValueStore) DeleteAllByCID(ctxID string)
DeleteAllByCID clears all key-value pairs for a given context from the store.
func (*KeyValueStore) DeleteByCID ¶ added in v0.9.5
func (kv *KeyValueStore) DeleteByCID(ctxID string, flags ...bool)
DeleteByCID removes all key-value pairs for a given context. Flags can be used to specify whether to delete persistent. If no flags are provided, only non-persistent entries are deleted. Flag[0] set is to delete persistent entries
func (*KeyValueStore) DeleteNonPersistent ¶ added in v0.9.5
func (kv *KeyValueStore) DeleteNonPersistent()
DeleteNonPersistent removes all key-value pairs that are not persistent.
func (*KeyValueStore) DeleteNonPersistentByCID ¶ added in v0.9.5
func (kv *KeyValueStore) DeleteNonPersistentByCID(ctxID string)
DeleteNonPersistentByCID removes all key-value pairs for a given context that are not persistent.
func (*KeyValueStore) Get ¶ added in v0.9.5
func (kv *KeyValueStore) Get(key string, ctxID string) (any, Properties, error)
Get retrieves the value (which could be string or []string) and properties for a given key and context.
func (*KeyValueStore) GetBySource ¶ added in v0.9.5
func (kv *KeyValueStore) GetBySource(key string, source string) (interface{}, Properties, error)
GetBySource retrieves the value and properties for a given key and source.
func (*KeyValueStore) GetCounterInfo ¶ added in v1.0.7
func (kv *KeyValueStore) GetCounterInfo(key string) (*CounterInfo, error)
GetCounterInfo returns a safe, read-only snapshot of a counter state.
func (*KeyValueStore) GetWithCtx ¶ added in v0.9.5
func (kv *KeyValueStore) GetWithCtx(key string, source string, ctxID string) (interface{}, Properties, error)
GetWithCtx retrieves the value for a given key, considering both Source and CtxID if provided.
func (*KeyValueStore) Increment ¶ added in v0.9.5
func (kv *KeyValueStore) Increment(key, ctxID string, step int64) (int64, error)
Increment increments the value for a given key and context by a specified step and it's thread safe.
func (*KeyValueStore) Keys ¶ added in v0.9.5
func (kv *KeyValueStore) Keys(ctxID string) []string
Keys returns a slice of all keys (without the CID) in the store for a given context.
func (*KeyValueStore) Release ¶ added in v1.0.7
func (kv *KeyValueStore) Release( key string, leaseID string, ) error
Release releases a previously acquired lease from the named counter. It is atomic and non-blocking. It returns an error if the counter or lease does not exist or if state is corrupted.
func (*KeyValueStore) Set ¶ added in v0.9.5
func (kv *KeyValueStore) Set(key string, value interface{}, properties Properties) error
Set sets a value (either string or []string) along with its properties for a given key and context.
func (*KeyValueStore) SetSharedCallback ¶ added in v0.9.5
func (kv *KeyValueStore) SetSharedCallback(callback SharedCallback)
SetSharedCallback sets the callback function for shared key-value store operations. This function should be called by the code that will use KVStore to set the callback.
func (*KeyValueStore) Size ¶ added in v0.9.5
func (kv *KeyValueStore) Size() int
Size returns the number of key-value pairs in the store.
func (*KeyValueStore) ToJSON ¶ added in v0.9.5
func (kv *KeyValueStore) ToJSON() string
ToJSON converts the key-value store to a JSON string. It uses json.Marshal to convert the value to the correct JSON format.
func (*KeyValueStore) TryAcquire ¶ added in v1.0.7
func (kv *KeyValueStore) TryAcquire( key string, slots int64, ttl time.Duration, owner string, ) (string, bool, error)
TryAcquire attempts to acquire `slots` capacity from the named counter. It is non-blocking and atomic. On success it returns (leaseID, true, nil). If capacity is insufficient it returns ("", false, nil). Errors are returned only for invalid usage or corrupted state.
func (*KeyValueStore) WithCounter ¶ added in v1.0.7
func (kv *KeyValueStore) WithCounter( key string, fn func(entry *Entry, cv *CounterValue) error, ) error
WithCounter is a helper function to safely access and modify a counter entry. we can't return the counter value directly because we need to ensure thread safety Important Note: WithCounter should only be used for mutations, not for read-only access. For read-only access, use Get and type assert the value to CounterValue.
type LoggerCfg ¶
type LoggerCfg struct {
// Type is the type of logger to use (stdout, file, syslog)
Type DbgLogType
// File is the file to write the logs to
File string
// Host is the syslog server to send the logs to
Host string
// Port is the syslog server port
Port int
// Tag is the syslog tag
Tag string
// Facility is the syslog facility
Facility string
// Priority is the syslog priority
Priority string
}
LoggerCfg is the logger configuration
type OpenAPIComponents ¶ added in v1.2.0
OpenAPIComponents represents the reusable components of the API, such as schemas, which can be referenced throughout the specification.
type OpenAPIContent ¶ added in v1.2.0
type OpenAPIContent struct {
//Schema OpenAPISchema `json:"schema"`
Schema any `json:"schema"`
}
OpenAPIContent represents the structure of the content for a specific media type in a request body, including its schema definition.
type OpenAPIInfo ¶ added in v1.2.0
type OpenAPIInfo struct {
Title string `json:"title"`
Version string `json:"version"`
Description string `json:"description,omitempty"`
}
OpenAPIInfo represents the metadata information about the API, including its title, version, and an optional description.
type OpenAPIOperation ¶ added in v1.2.0
type OpenAPIOperation struct {
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
OperationID string `json:"operationId,omitempty"`
Tags []string `json:"tags,omitempty"`
Parameters []OpenAPIParameter `json:"parameters,omitempty"`
RequestBody *OpenAPIRequestBody `json:"requestBody,omitempty"`
Responses map[string]OpenAPIResponse `json:"responses"`
}
OpenAPIOperation represents the structure of an API operation, including its summary, description, operation ID, tags, parameters, request body, and responses.
type OpenAPIOptions ¶ added in v1.2.0
type OpenAPIOptions struct {
Title string
Version string
Description string
ServerURL string // optional, e.g. "http://localhost:8080"
}
OpenAPIOptions represents the options for generating an OpenAPI specification, including the title, version, description, and an optional server URL for the API.
type OpenAPIParameter ¶ added in v1.2.0
type OpenAPIParameter struct {
Name string `json:"name"`
In string `json:"in"`
Required bool `json:"required,omitempty"`
Description string `json:"description,omitempty"`
Schema OpenAPISchema `json:"schema"`
}
OpenAPIParameter represents the structure of a parameter used in an API operation, including its name, location (e.g., query, path, header), whether it is required, a description, and its schema definition.
type OpenAPIPath ¶ added in v1.2.0
type OpenAPIPath map[string]OpenAPIOperation
OpenAPIPath represents the structure of an API path, which maps HTTP methods to their corresponding operations (e.g., GET, POST, etc.).
type OpenAPIRequestBody ¶ added in v1.2.0
type OpenAPIRequestBody struct {
Required bool `json:"required,omitempty"`
Content map[string]OpenAPIContent `json:"content"`
}
OpenAPIRequestBody represents the structure of a request body used in an API operation, including whether it is required and the content types it supports, along with their corresponding schema definitions.
type OpenAPIResponse ¶ added in v1.2.0
type OpenAPIResponse struct {
Description string `json:"description"`
Content map[string]OpenAPIContent `json:"content,omitempty"`
}
OpenAPIResponse represents the structure of a response for an API operation, including its description and any additional metadata that may be relevant for documenting the response.
type OpenAPISchema ¶ added in v1.2.0
type OpenAPISchema struct {
Type string `json:"type,omitempty"`
Properties map[string]OpenAPISchema `json:"properties,omitempty"`
Items *OpenAPISchema `json:"items,omitempty"`
AdditionalProperties any `json:"additionalProperties,omitempty"`
Format string `json:"format,omitempty"`
Required []string `json:"required,omitempty"`
}
OpenAPISchema represents the structure of a schema definition used in parameters, request bodies, and responses, including its type, properties (for object types), and items (for array types).
type OpenAPIServer ¶ added in v1.2.0
type OpenAPIServer struct {
URL string `json:"url"`
Description string `json:"description,omitempty"`
}
OpenAPIServer represents a server that serves the API, including its URL and an optional description.
type OpenAPISpec ¶ added in v1.2.0
type OpenAPISpec struct {
OpenAPI string `json:"openapi"`
Info OpenAPIInfo `json:"info"`
Servers []OpenAPIServer `json:"servers,omitempty"`
Paths map[string]OpenAPIPath `json:"paths"`
Components OpenAPIComponents `json:"components,omitempty"`
}
OpenAPISpec represents the structure of an OpenAPI specification, including the OpenAPI version, API information, servers, paths, and components.
func BuildOpenAPISpec ¶ added in v1.2.0
func BuildOpenAPISpec(routes []APIRoute, opt OpenAPIOptions) OpenAPISpec
BuildOpenAPISpec generates an OpenAPI specification based on the registered API routes and the provided options.
type OutboundAuthConfig ¶ added in v1.2.0
type Properties ¶ added in v0.9.5
type Properties struct {
Persistent bool `yaml:"persistent"` // Whether the entry should be persistent
Static bool `yaml:"static"` // Whether the entry should be static
SessionValid bool `yaml:"session_valid"` // Whether the entry should be valid for the session
Source string `yaml:"source"` // The source of the key-value entry
CtxID string // Context ID for more specific identification
Type string // The type of the stored value (e.g., "string", "[]string")
}
Properties defines the additional attributes for each key-value entry.
func NewKVStoreEmptyProperty ¶ added in v0.9.5
func NewKVStoreEmptyProperty() Properties
NewKVStoreEmptyProperty initializes a new Properties object with default values.
func NewKVStoreProperty ¶ added in v0.9.5
func NewKVStoreProperty(persistent bool, static bool, sessionValid bool, shared bool, source string, ctxID string, Type string) Properties
NewKVStoreProperty initializes a new Properties object.
type SafeMutex ¶ added in v0.9.5
type SafeMutex struct {
// contains filtered or unexported fields
}
SafeMutex is a thread-safe mutex that ensures that the lock is only released if it was previously locked.
type SharedCallback ¶ added in v0.9.5
type SharedCallback func(action, key string, value interface{}, props Properties)
SharedCallback is a callback function type for shared key-value store operations. It's used to notify the cluster sharing API when a key-value pair is set or updated. It needs to be implemented by the code that will use KVStore. The callback function should accept the action (set, update or delete), key, value, and properties as parameters.
type StdAPIError ¶ added in v1.2.0
type StdAPIError struct {
ErrCode int `json:"error_code"`
Err string `json:"error"`
Message string `json:"message"`
}
StdAPIError represents a standard error response structure for API endpoints, including an error code, a short error message, and a more detailed message that can provide additional context about the error.
type StdAPIQuery ¶ added in v1.2.0
type StdAPIQuery struct {
Q string `` /* 327-byte string literal not displayed */
Limit int `` /* 217-byte string literal not displayed */
Offset int `` /* 229-byte string literal not displayed */
}
StdAPIQuery represents a standard query structure that can be used for API endpoints that support querying with pagination.
type StdAPISuccess ¶ added in v1.2.0
StdAPISuccess represents a standard success response structure for API endpoints, including an operation code and a message that can provide additional context about the successful operation.
type UserAgent ¶ added in v0.9.5
type UserAgent struct {
// BR is the actual browser name
BR string `json:"br" yaml:"br"`
// UA is the user agent string
UA string `json:"ua" yaml:"ua"`
// PCT is the percentage of the user agent
PCT float64 `json:"pct" yaml:"pct"`
}
UserAgent represents a user agent with its string and percentage.
type UserAgentGroup ¶ added in v0.9.5
type UserAgentGroup struct {
// OS is the operating system
OS string `json:"os" yaml:"os"`
// BRG is the browser group (e.g. "chrome" identify all chrome related browsers)
BRG string `json:"brg" yaml:"brg"`
// Type identify the type of user agent (desktop or mobile)
Type string // Type is added manually ("desktop" or "mobile")
// UserAgents is a list of user agents
UserAgents []UserAgent `json:"ua" yaml:"ua"`
}
UserAgentGroup represents a group of user agents with metadata.
type UserAgentsDB ¶ added in v0.9.5
type UserAgentsDB struct {
// UserAgentsGroups is a list of user agent groups
UserAgentsGroups []UserAgentGroup
}
UserAgentsDB represents the entire user agents database.
var UADB UserAgentsDB
UADB is the global user agents database.
func (*UserAgentsDB) GetAgentByTypeAndOS ¶ added in v0.9.5
func (uaDB *UserAgentsDB) GetAgentByTypeAndOS(uaType, os string) string
GetAgentByTypeAndOS returns a random user agent string from the database based on the type and OS.
func (*UserAgentsDB) GetAgentByTypeAndOSAndBRG ¶ added in v0.9.5
func (uaDB *UserAgentsDB) GetAgentByTypeAndOSAndBRG(uaType, os, brg string) string
GetAgentByTypeAndOSAndBRG returns a random user agent string from the database based on the type, OS, and BRG.
func (*UserAgentsDB) GetAgentByTypeAndOSAndBRGAndPCT ¶ added in v0.9.5
func (uaDB *UserAgentsDB) GetAgentByTypeAndOSAndBRGAndPCT(uaType, os, brg string, pct float64) string
GetAgentByTypeAndOSAndBRGAndPCT returns a random user agent string from the database based on the type, OS, BRG, and PCT.
func (*UserAgentsDB) GetAnyUserAgent ¶ added in v0.9.5
func (uaDB *UserAgentsDB) GetAnyUserAgent() string
GetAnyUserAgent returns a random user agent string from the database.
func (*UserAgentsDB) InitUserAgentsDB ¶ added in v0.9.5
func (uaDB *UserAgentsDB) InitUserAgentsDB() error
InitUserAgentsDB initializes the user agents database.
func (*UserAgentsDB) IsEmpty ¶ added in v0.9.5
func (uaDB *UserAgentsDB) IsEmpty() bool
IsEmpty checks if the user agents database is empty.