hook

package
v1.7.13 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2025 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func GetHookRoles(location, method string) []string

GetHookRoles returns the roles required for a specific hook.

func HasRequiredRoles added in v1.7.0

func HasRequiredRoles(ctx *gin.Context, location, method string) bool

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

func PreCompileLuaScript(filePath string) (err error)

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

func RunLuaHook(ctx *gin.Context) (gin.H, error)

RunLuaHook executes a precompiled Lua script based on a hook parameter from the gin.Context.

func RunLuaInit

func RunLuaInit(ctx context.Context, hook string) error

RunLuaInit initializes and runs a Lua script based on the specified hook.

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.

Jump to

Keyboard shortcuts

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