feature

package
v0.0.0-...-9d1dd97 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

LuaPool is a pool of Lua state instances.

Functions

func PreCompileLuaFeatures

func PreCompileLuaFeatures() (err error)

PreCompileLuaFeatures pre-compiles Lua features. It checks if the configuration for Lua features is loaded and if the LuaFeatures variable is already set. If the LuaFeatures variable is not set, it creates a new instance of PreCompiledLuaFeatures. If the LuaFeatures variable is already set, it resets it using the Reset method. Then it loops through the features in the configuration and creates a new LuaFeature instance for each feature. The LuaFeature instance is created using the NewLuaFeature function, passing the name and script path from the configuration. If there is an error creating the LuaFeature instance, the error is returned. The compiled Lua feature is added to the LuaFeatures variable using the Add method. Finally, it returns nil if there are no errors.

Types

type LuaFeature

type LuaFeature struct {
	Name           string
	CompiledScript *lua.FunctionProto
}

LuaFeature represents a Lua feature that has been compiled. It contains a name identifying the feature and the compiled Lua script.

func NewLuaFeature

func NewLuaFeature(name string, scriptPath string) (*LuaFeature, error)

NewLuaFeature creates a new instance of LuaFeature with the given name and script path. If the name or script path is empty, it returns an error. The function compiles the Lua script using lualib.CompileLua and assigns the compiled script to the CompiledScript field of the LuaFeature. The function returns the created LuaFeature instance and nil error if successful. Otherwise, it returns nil and the appropriate error.

type PreCompiledLuaFeatures

type PreCompiledLuaFeatures struct {
	LuaScripts []*LuaFeature
	Mu         sync.RWMutex
}

PreCompiledLuaFeatures represents a collection of pre-compiled Lua features. It contains an array of LuaFeature objects and a read-write mutex for synchronization.

var LuaFeatures *PreCompiledLuaFeatures

LuaFeatures is a pointer to a PreCompiledLuaFeatures object. It represents a collection of pre-compiled Lua scripts that can be executed.

The PreCompiledLuaFeatures struct has the following properties: - `LuaScripts`: a slice of LuaFeature objects representing the individual pre-compiled Lua scripts. - `mu`: a mutex used to synchronize access to the LuaScripts slice.

The PreCompiledLuaFeatures has two methods: - `Add(luaFeature *LuaFeature)`: adds a LuaFeature object to the LuaScripts slice. - `Reset()`: clears the LuaScripts slice.

Usage example: The PreCompileLuaFeatures function initializes the LuaFeatures variable by pre-compiling the Lua scripts specified in the configuration.

The CallFeatureLua method of the Request struct executes the pre-compiled Lua scripts stored in LuaFeatures on the provided gin.Context. It retrieves a read lock on the LuaFeatures object and creates a new Lua state. It then sets up the necessary Lua libraries and global variables. The executeScripts method is called to execute each pre-compiled Lua script in order, passing in the request and the Lua state. If a script triggers or aborts the execution of features, the execution is halted and the method returns the appropriate values.

func (*PreCompiledLuaFeatures) Add

func (a *PreCompiledLuaFeatures) Add(luaFeature *LuaFeature)

Add appends the given LuaFeature to the slice of LuaScripts in PreCompiledLuaFeatures.

func (*PreCompiledLuaFeatures) Reset

func (a *PreCompiledLuaFeatures) Reset()

Reset resets the slice of LuaScripts in PreCompiledLuaFeatures by creating a new empty slice. The method also acquires a lock on the PreCompiledLuaFeatures mutex before resetting the slice and defers the unlocking of the mutex until the method returns.

type Request

type Request struct {
	// Debug is a flag indicating whether debug mode is on.
	Debug bool

	// Session is a GUID representing a unique session identifier.
	Session string

	// ClientIP is the IP address of the client making the request.
	ClientIP string

	// ClientPort is the network port being used by the client.
	ClientPort string

	// Username refers to the username used for authentication purposes.
	Username string

	// Password is associated with the username for authentication.
	Password string

	// Protocol represents the communication protocol used for the request.
	Protocol string

	// ClientID is a unique identifier for the client.
	ClientID string

	// LocalIP is the local IP address.
	LocalIP string

	// LocalPort is the local network port.
	LocalPort string

	// UserAgent is the user agent used by the client making the request.
	UserAgent 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

	// Logs holds the custom log key-value pairs.
	Logs *lualib.CustomLogKeyValue

	// Context contains additional context data.
	*lualib.Context
}

Request represents a request data structure with all the necessary information about a connection and SSL usage.

func (*Request) CallFeatureLua

func (r *Request) CallFeatureLua(ctx *gin.Context) (triggered bool, abortFeatures bool, err error)

CallFeatureLua executes Lua scripts for a given request context. It acquires a read lock on the LuaFeatures mutex. It creates a new Lua state and preloads necessary libraries. It sets global variables in the Lua state. It sets fields for the request in the Lua state. It executes the Lua scripts for the request. It returns the triggered flag, abortFeatures flag, and related error if any.

Jump to

Keyboard shortcuts

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