Documentation
¶
Index ¶
- Variables
- func GetHookRoles(location, method string) []string
- func HasRequiredRoles(ctx *gin.Context, location, method string) bool
- func InitHTTPClient()
- func PreCompileLuaHooks() error
- func PreCompileLuaScript(filePath string) (err error)
- func RunLuaHook(ctx *gin.Context) (gin.H, error)
- func RunLuaInit(ctx context.Context, hook string) error
- type CustomHook
- type CustomLocation
- type HttpMethod
- type Location
- type PrecompiledLuaScript
Constants ¶
This section is empty.
Variables ¶
var ( // LuaScripts is a map that stores precompiled Lua scripts, allowing safe concurrent access and manipulation. LuaScripts = make(map[string]*PrecompiledLuaScript) )
Functions ¶
func GetHookRoles ¶ added in v1.7.0
GetHookRoles returns the roles required for a specific hook.
func HasRequiredRoles ¶ added in v1.7.0
HasRequiredRoles checks if the user has any of the required roles for a hook. If no roles are configured for the hook, it returns true (allowing access). If JWT is not enabled or not properly configured, it returns true (allowing access).
func InitHTTPClient ¶
func InitHTTPClient()
InitHTTPClient initializes the global httpClient variable with a pre-configured instance from util.NewHTTPClient.
func PreCompileLuaHooks ¶ added in v1.3.9
func PreCompileLuaHooks() error
PreCompileLuaHooks pre-compiles Lua hook scripts defined in the configuration and assigns them to specified locations and methods. It also stores the roles associated with each hook for role-based access control. Returns an error if the compilation or setup fails.
func PreCompileLuaScript ¶
PreCompileLuaScript compiles a Lua script from the specified file path and manages the script in a thread-safe map. Updates or removes entries in the LuaScripts map based on the configuration and compilation status. Returns an error if the compilation fails or if the script cannot be managed properly.
func RunLuaHook ¶ added in v1.3.9
RunLuaHook executes a precompiled Lua script based on a hook parameter from the gin.Context.
Types ¶
type CustomHook ¶ added in v1.3.9
type CustomHook map[HttpMethod]*PrecompiledLuaScript
CustomHook maps an HTTP method to its corresponding precompiled Lua script for handling specific requests.
func NewCustomHook ¶ added in v1.3.9
func NewCustomHook(httpMethod string, script *PrecompiledLuaScript) CustomHook
NewCustomHook creates a new CustomHook with the specified HTTP method and precompiled Lua script.
func (CustomHook) GetScript ¶ added in v1.3.9
func (h CustomHook) GetScript(method string) *PrecompiledLuaScript
GetScript retrieves the precompiled Lua script associated with the specified HTTP method from the CustomHook. Returns the Lua script if found, otherwise returns nil.
func (CustomHook) SetScript ¶ added in v1.3.9
func (h CustomHook) SetScript(method string, script *PrecompiledLuaScript)
SetScript associates a precompiled Lua script with a specific HTTP method in the CustomHook.
type CustomLocation ¶ added in v1.3.9
type CustomLocation map[Location]CustomHook
CustomLocation is a map where each key is a Location and each value is a CustomHook.
func NewCustomLocation ¶ added in v1.3.9
func NewCustomLocation() CustomLocation
NewCustomLocation creates a new CustomLocation, which is a map of Location keys to CustomHook values.
func (CustomLocation) GetCustomHook ¶ added in v1.3.9
func (l CustomLocation) GetCustomHook(location string) CustomHook
GetCustomHook retrieves a CustomHook associated with the given location string. Returns the CustomHook if found, otherwise returns nil.
func (CustomLocation) GetScript ¶ added in v1.3.9
func (l CustomLocation) GetScript(location, method string) *PrecompiledLuaScript
GetScript retrieves a precompiled Lua script based on the provided location and HTTP method. Returns the script or nil.
func (CustomLocation) SetScript ¶ added in v1.3.9
func (l CustomLocation) SetScript(location, method string, script *PrecompiledLuaScript)
SetScript assigns a precompiled Lua script to a specific HTTP method for the given location.
type HttpMethod ¶ added in v1.3.9
type HttpMethod string
HttpMethod represents the HTTP methods used in HTTP requests.
type Location ¶ added in v1.3.9
type Location string
Location represents a string type specifically used to denote a location.
type PrecompiledLuaScript ¶
type PrecompiledLuaScript struct {
// contains filtered or unexported fields
}
PrecompiledLuaScript represents a type that holds a precompiled Lua script and allows safe concurrent access to the script.
func NewLuaHook ¶
func NewLuaHook(filePath string) (*PrecompiledLuaScript, error)
NewLuaHook compiles a Lua script from the given file path and returns a PrecompiledLuaScript instance or an error.
func (*PrecompiledLuaScript) GetPrecompiledScript ¶
func (p *PrecompiledLuaScript) GetPrecompiledScript() *lua.FunctionProto
GetPrecompiledScript retrieves the stored precompiled Lua script (*lua.FunctionProto) with read lock for thread safety.
func (*PrecompiledLuaScript) Replace ¶
func (p *PrecompiledLuaScript) Replace(luaScript *PrecompiledLuaScript)
Replace updates the luaScript field of the current PrecompiledLuaScript instance with the luaScript from the provided instance.