Documentation ¶
Index ¶
- func AddCustomLog(keyval *CustomLogKeyValue) lua.LGFunction
- func CheckBackendConnection() lua.LGFunction
- func CleanupLTable(table *lua.LTable)
- func CompileLua(filePath string) (*lua.FunctionProto, error)
- func ContextDelete(ctx *Context) lua.LGFunction
- func ContextGet(ctx *Context) lua.LGFunction
- func ContextSet(ctx *Context) lua.LGFunction
- func DoCompiledFile(L *lua.LState, proto *lua.FunctionProto) error
- func GetAllHTTPRequestHeaders(httpRequest *http.Request) lua.LGFunction
- func Loader(L *lua.LState) int
- func LuaTableToMap(table *lua.LTable) map[any]any
- func MapToLuaTable(L *lua.LState, table map[any]any) *lua.LTable
- func NewLStateWithDefaultLibraries() *lua.LState
- func PackagePath(L *lua.LState) error
- func RedisDel(L *lua.LState) int
- func RedisExpire(L *lua.LState) int
- func RedisGet(L *lua.LState) int
- func RedisIncr(L *lua.LState) int
- func RedisSet(L *lua.LState) int
- func SetStatusMessage(status **string) lua.LGFunction
- func SliceToLuaTable(L *lua.LState, slice []any) *lua.LTable
- type CommonRequest
- type Context
- type CustomLogKeyValue
- type Done
- type LStateProvider
- type LuaBackendResult
- type LuaBackendResultStatePool
- type LuaBaseStatePool
- type LuaStatePool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddCustomLog ¶
func AddCustomLog(keyval *CustomLogKeyValue) lua.LGFunction
func CheckBackendConnection ¶
func CheckBackendConnection() lua.LGFunction
func CleanupLTable ¶
func CompileLua ¶
func CompileLua(filePath string) (*lua.FunctionProto, error)
CompileLua reads the passed lua file from disk and compiles it.
func ContextDelete ¶
func ContextDelete(ctx *Context) lua.LGFunction
ContextDelete is a wrapper function to Context.Delete(...). The argument ctx provides the Lua context for the underlying Lua function.
func ContextGet ¶
func ContextGet(ctx *Context) lua.LGFunction
ContextGet is a wrapper function to Context.Get(...). The argument ctx provides the Lua context for the underlying Lua function.
func ContextSet ¶
func ContextSet(ctx *Context) lua.LGFunction
ContextSet is a wrapper function to Context.Set(...). The argument ctx provides the Lua context for the underlying Lua function.
func DoCompiledFile ¶
func DoCompiledFile(L *lua.LState, proto *lua.FunctionProto) error
DoCompiledFile takes a FunctionProto, as returned by CompileLua, and runs it in the LState. It is equivalent to calling DoFile on the LState with the original source file.
func GetAllHTTPRequestHeaders ¶
func GetAllHTTPRequestHeaders(httpRequest *http.Request) lua.LGFunction
GetAllHTTPRequestHeaders returns a LGFunction that creates a Lua table containing all headers from the http.Request object The table is indexed by the lowercase header name and each header's value is a list of strings The function expects a *http.Request object as its parameter
Example usage:
headers := getAllHeaders(request) L.SetGlobal("getAllHeaders", L.NewClosure(headers)) result := L.DoString(` local headers = getAllHeaders() print(headers["content-type"][1]) -- print the first value of the "content-type" header `) if result != nil { fmt.Println("Error:", result) }
func Loader ¶
func Loader(L *lua.LState) int
Loader takes a *lua.LState as input and initializes a new module by setting the functions from `exports` into a new lua.LTable. The module table is then pushed onto the top of the stack. Finally, it returns 1 to indicate that one value has been returned to Lua.
func LuaTableToMap ¶
LuaTableToMap takes a lua.LTable as input and converts it into a map[any]any. The function iterates over each key-value pair in the table and converts the keys and values into their corresponding Go types. The converted key-value pairs are then added to a new map, which is returned as the result. If the input table is nil, the function returns nil.
func MapToLuaTable ¶
MapToLuaTable takes an *lua.LState and a map[any]any as input and converts it into a *lua.LTable. The function iterates over each key-value pair in the map and converts the keys and values into their corresponding lua.LValue types. The converted key-value pairs are then added to a new *lua.LTable, which is returned as the result. If the input map is nil, the function returns nil.
func NewLStateWithDefaultLibraries ¶
NewLStateWithDefaultLibraries initializes a new Lua state with default libraries. It creates a new instance of *lua.LState using lua.NewState(). It then loads the libraries using libs.Preload() and gluacrypto.Preload(). Finally, it returns the initialized Lua state. Usage: L := NewLStateWithDefaultLibraries() Note: The returned Lua state is not thread-safe. It is recommended to use a state pool for managing Lua states in a concurrent environment.
func PackagePath ¶
PackagePath sets the Lua package path to include the directory where the Lua modules reside. It appends the Lua package path with the value returned by `config.LoadableConfig.GetLuaPackagePath()`. This function takes a Lua state (`*lua.LState`) as an argument and returns an error.
func RedisDel ¶
RedisDel deletes the value associated with the given key from the Redis server. It returns "OK" as a Lua string if the delete operation is successful. If an error occurs, it returns nil and the error message as a Lua string. The function expects one argument: the key to delete.
func RedisExpire ¶
RedisExpire sets a timeout on the specified key in the Redis server. It expects two arguments: the key and the expiration time in seconds. If the operation succeeds, it returns "OK" as a Lua string. If an error occurs, it returns nil and the error message as a Lua string. Example usage: result = redis_expire("mykey", 60)
func RedisGet ¶
RedisGet retrieves the value associated with the given key from the Redis server. It returns the value as a Lua string. If an error occurs, it returns nil and the error message as a Lua string. The function expects one argument: the key to retrieve. Example usage: val = redis_get_str("mykey")
func RedisIncr ¶
RedisIncr increments the value associated with the given key in the Redis server. It returns the incremented value as a Lua number. If an error occurs, it returns nil and the error message as a Lua string. The function expects one argument: the key to increment. Example usage: val = redis_incr("counter")
func RedisSet ¶
RedisSet sets the value of the given key to the provided value in the Redis server. It returns "OK" as a Lua string if the operation is successful. If an error occurs, it returns nil and the error message as a Lua string. The function expects two arguments: the key and the value to set.
func SetStatusMessage ¶
func SetStatusMessage(status **string) lua.LGFunction
func SliceToLuaTable ¶
func SliceToLuaTable(L *lua.LState, slice []any) *lua.LTable
SliceToLuaTable converts a slice into a Lua table using the provided Lua state. It accepts two parameters:
- L: a pointer to the Lua state
- slice: a slice of type `any`
For each value in the slice, the function checks the type of the value. If the value is a boolean, it sets the Lua table's element at index `i+1` to a Lua boolean with the same value. If the value is a float64, it sets the Lua table's element at index `i+1` to a Lua number with the same value. If the value is a string, it sets the Lua table's element at the index `i+1` to a Lua string with the same value.
If the value is of any other type, the function returns nil.
Finally, the function returns a pointer to a Lua table that contains all valid values from the slice.
Types ¶
type CommonRequest ¶
type CommonRequest struct { // Debug is a flag indicating if the action is executed in debug mode. Debug bool // Repeating is a flag indicating if the action would be repeated. Repeating bool // UserFound is a flag indicating if the user executing the action was found in the system. UserFound bool // Authenticated is a flag indicating if the user is authenticated. Authenticated bool // NoAuth is a flag indicating if the action requires no authentication. NoAuth bool // BruteForceCounter keeps track of unsuccessful login attempts for the user. BruteForceCounter uint // Service is the http routers endpoint name. Service string // Session stores the unique session identifier. Session string // GUID // ClientIP stores the IP address of the client. ClientIP string // ClientPort stores the port number used by the client. ClientPort string // ClientNet stores the network used by the client. ClientNet string // ClientHost stores the hostname of the client. ClientHost string // ClientID stores the unique identifier for the client. ClientID string // UserAgent stores toe User-Agent of the client. UserAgent string // LocalIP stores the IP address of the local machine. LocalIP string // LocalPort stores the port number used by the local machine. LocalPort string // Username stores the username of the user that was used to authenticate. Username string // Account stores the user's account information. Account string // UniqueUserID stores the unique user identifier. UniqueUserID string // DisplayName stores the user's display name. DisplayName string // Password stores the user's password. Password string // Protocol stores the protocol that the user used to authenticate. Protocol string // BruteForceName stores the name of the brute force protection mechanism. BruteForceName string // FeatureName is a feature that triggered the action. FeatureName string // StatusMessage is a configurable message that is returned to the client upon errors (not tempfail). StatusMessage *string // XSSL contains SSL information. XSSL string // XSSLSessionID is the SSL session identifier. XSSLSessionID string // XSSLClientVerify indicates whether SSL client is verified. XSSLClientVerify string // XSSLClientDN is the client's Distinguished Name in the SSL certificate. XSSLClientDN string // XSSLClientCN is the client's Common Name in the SSL certificate. XSSLClientCN string // XSSLIssuer is the issuer of the SSL certificate. XSSLIssuer string // XSSLClientNotBefore is the date before which the SSL certificate is not valid. XSSLClientNotBefore string // XSSLClientNotAfter is the date after which the SSL certificate is not valid. XSSLClientNotAfter string // XSSLSubjectDN is the Subject's Distinguished Name in the SSL certificate. XSSLSubjectDN string // XSSLIssuerDN is the Issuer's Distinguished Name in the SSL certificate. XSSLIssuerDN string // XSSLClientSubjectDN is the client's Subject Distinguished Name in the SSL certificate. XSSLClientSubjectDN string // XSSLClientIssuerDN is the client's Issuer Distinguished Name in the SSL certificate. XSSLClientIssuerDN string // XSSLProtocol is the SSL protocol used. XSSLProtocol string // XSSLCipher is the encryption cipher used in the SSL protocol. XSSLCipher string }
CommonRequest represents a common request object with various properties used in different functionalities.
func (*CommonRequest) SetupRequest ¶
func (c *CommonRequest) SetupRequest(request *lua.LTable) *lua.LTable
SetupRequest sets up the request object with the common request properties
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is a system-wide Lua context designed to exchange Lua LValues between all Lua levels. Even it implements all methodes from Context, its use is limitted to data exchange. It can not be used to abort running threads. Usage of this context is thread safe.
func (*Context) Get ¶
Get returns the lua.LValue value aquired by key from the Lua Context. If no key was found, it returns nil.
type CustomLogKeyValue ¶
type CustomLogKeyValue []any
type LStateProvider ¶
LStateProvider is a function type that returns a pointer to a lua.LState. It represents a provider function that can be used to create new lua.LState instances.
type LuaBackendResult ¶
type LuaBackendResult struct { // Authenticated represents whether the user is authenticated or not Authenticated bool // UserFound indicates whether the user was found in the system or not UserFound bool // AccountField is the field associated with the user's account AccountField string // TOTPSecretField is the field that holds the user's TOTP Secret TOTPSecretField string // TOTPRecoveryField is the field for the user's TOTP recovery code TOTPRecoveryField string // UniqueUserIDField is the unique user id field UniqueUserIDField string // DisplayNameField is the display name associated with the user's account DisplayNameField string // Err captures any error that occurred during the backend process Err error // Attributes holds any other attributes related to the user's account Attributes map[any]any // Logs is a pointer to a custom log key-value pair associated with the Lua script. Logs *CustomLogKeyValue }
LuaBackendResult holds the response returned by the Lua backend. Information about user authentication, user account, and error details are encapsulated in this data structure.
type LuaBackendResultStatePool ¶
type LuaBackendResultStatePool struct {
*LuaStatePool
}
LuaBackendResultStatePool embeds the LuaStatePool type. It provides methods for retrieving, returning, and shutting down Lua states.
type LuaBaseStatePool ¶
type LuaBaseStatePool interface { // Get retrieves a Lua state from the pool. Get() *lua.LState // Put returns a Lua state to the pool. Put(L *lua.LState) // Shutdown closes all the Lua states in the pool. Shutdown() // LogStatistics logs debugging information about the pool. LogStatistics(poolName string) }
LuaBaseStatePool is an interface for managing a pool of Lua state instances. If there are no available states in the pool, a new state is created.
func NewLuaBackendResultStatePool ¶
func NewLuaBackendResultStatePool(methods ...string) LuaBaseStatePool
NewLuaBackendResultStatePool creates a new instance of LuaBackendResultStatePool that implements the LuaBaseStatePool interface. It initializes a LuaStatePool with a New function
func NewLuaStatePool ¶
func NewLuaStatePool() LuaBaseStatePool
NewLuaStatePool initializes a new Lua state pool. It creates a new instance of LuaStatePool with the New function set to NewLStateWithDefaultLibraries. It then calls InitializeStatePool to initialize the pool and return the initialized pool. Usage: luaPool := NewLuaStatePool()
type LuaStatePool ¶
type LuaStatePool struct { Mu sync.Mutex New LStateProvider MaxStates int // Maximum allowed states in the pool Cond sync.Cond // A condition variable to signal availability of Lua states in the pool // contains filtered or unexported fields }
LuaStatePool is a type for managing a pool of Lua state instances. The pool uses a sync.Mutex to ensure safe concurrent access. The saved field is a slice of *lua.LState, which holds the available Lua states in the pool. The New field is an LStateProvider function, which is used to create new Lua states when the pool is empty.
func (*LuaStatePool) Get ¶
func (pl *LuaStatePool) Get() *lua.LState
Get returns a Lua state from the pool. It locks the mutex of the LuaStatePool to ensure thread safety. If there are no saved Lua states in the pool, it calls the New function of the LuaStatePool to create a new Lua state. Otherwise, it retrieves the last saved Lua state from the pool and removes it from the slice. Finally, it returns the retrieved Lua state.
func (*LuaStatePool) InitializeStatePool ¶
func (pl *LuaStatePool) InitializeStatePool() *LuaStatePool
InitializeStatePool initializes the state pool. If the pool is nil, it returns nil. It creates a new slice with a capacity of 4 for storing Lua states. It updates the saved field of the pool with the new slice. Finally, it returns the pool.
func (*LuaStatePool) LogStatistics ¶
func (pl *LuaStatePool) LogStatistics(pool string)
LogStatistics logs the statistics of the Lua states in the pool. It calls the DebugModule function from the util package to log the statistics. The module parameter represents the name of the pool. It retrieves the number of Lua states in the pool using the len function. It retrieves the total size of the saved Lua states in the pool using the getLStateSizes function. The DebugModule function logs the number of Lua states in the pool and the size of the saved Lua states. The logging is conditional based on the verbosity level defined in config.EnvConfig.Verbosity.Level.
func (*LuaStatePool) Put ¶
func (pl *LuaStatePool) Put(L *lua.LState)
Put adds a new Lua state to the pool. It is thread-safe and uses mutex locking to ensure that the shared 'saved' slice is not accessed concurrently.
Parameters:
L: The *lua.LState instance to be added to the pool.
Returns:
None
func (*LuaStatePool) Shutdown ¶
func (pl *LuaStatePool) Shutdown()
Shutdown closes all the saved Lua states in the pool. It iterates over each saved Lua state in the slice and calls its Close method to close it.