script

package
v0.0.0-...-25bf8ac Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(path, defaultScript string) (*Manager, error)

func (*Manager) Reload

func (m *Manager) Reload()

func (*Manager) Script

func (m *Manager) Script() *Script

type Script

type Script struct {
	// contains filtered or unexported fields
}

A Script is a compiled Tengo script that will be executed on every request in order to provide a final reputation score for an IP.

The script will have a few global variables available:

'ip' is the IP being looked up

'counts' is a map[string]int64 of counters returned from the database in the chosen time interval

'interval' is the duration in seconds of the time interval chosen for this evaluation, so one can compute rates

To return the final reputation score (in the range 0 - 1), the script should set the 'score' variable.

func LoadScript

func LoadScript(path string) (*Script, error)

LoadScript creates a new Script by loading its source from the specified file.

func NewScript

func NewScript(src []byte) (*Script, error)

NewScript creates a new Script with the given source.

func (*Script) RunIP

func (s *Script) RunIP(ctx context.Context, ip string, counts map[string]int64, intervalSecs float64, extSrcs map[string]ext.ExternalSource) (float64, error)

RunIP evaluates the script once with the provided context and returns the resulting score.

Jump to

Keyboard shortcuts

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