koala

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ALLOW .允许
	ALLOW = 1
	// DENY 拒绝
	DENY = 2
)
View Source
const (
	// BaseKeySuffix base附加cache key的后缀;在getCacheKey()的key后追加
	BaseKeySuffix = "_B"
)

Variables

View Source
var (
	// Config koala基本配置
	Config *utility.Config
	// RedisPool 全局redis连接池
	RedisPool *redis.Pool

	// PolicyMd5 .
	// 全局 md5 值
	// 说明:定期检查 rule配置的变化,与此 md5 比较;实现动态更新规则
	PolicyMd5 string

	// DynamicUpdateFiles .
	// 需要检查更新的文件列表
	// 范围:rule 文件 + dicts 文件
	// 赋值:每次reload规则时,将其中的 dicts 文件记录于此
	DynamicUpdateFiles []string
)

@Project: koala @Author: houseme @Description: @File: koala @Version: 1.0.0 @Date: 2021/7/13 00:16 @Package koala

View Source
var (
	// PolicyCounter .
	PolicyCounter map[string]map[int32]*Counter
	// CountTransChannel .
	CountTransChannel chan *CountMessage
)

Functions

func CounterAgent

func CounterAgent()

CounterAgent 从 channel 里获取策略结果,然后定期写入日志 channel

func CounterClient

func CounterClient(ruleNo int32, deny bool)

CounterClient 统计API

func FrontDispatch

func FrontDispatch(httpConnection *utility.HttpConnection)

FrontDispatch .

func FrontListen

func FrontListen()

FrontListen .

func GetCurrentCounters

func GetCurrentCounters() map[int32]*Counter

GetCurrentCounters .

func GetDateString

func GetDateString(t time.Time) string

GetDateString .

func InitRedisPool

func InitRedisPool()

InitRedisPool redis连接池初始化函数

func IsIPAddress

func IsIPAddress(s string) bool

IsIPAddress 判断字符串是否是 IP 地址

func NewConfig

func NewConfig() *utility.Config

NewConfig 启动前加载配置文件

func NewPolicyMD5

func NewPolicyMD5() string

NewPolicyMD5 PolicyMd5 初始化函数

func PolicyInterpreter

func PolicyInterpreter(extStream string) error

PolicyInterpreter Policy解释器,用于从文件解析配置,记录到 Policy 结构中

func PolicyLoader

func PolicyLoader()

PolicyLoader . policy实时更新函数 说明:用于实时更新rule配置,解析过程调用PolicyInterpreter()处理

func PolicyMD5Str

func PolicyMD5Str() (string, error)

PolicyMD5Str 计算 DynamicUpdateFiles 所包含文件的 md5 值

func RuleUpdateLogic

func RuleUpdateLogic(request *utility.HttpRequest, logHandle *utility.Logger)

RuleUpdateLogic 更新操作执行函数

func Run

func Run()

Run .

func SavePid

func SavePid(pidFile string)

SavePid 进程 pid 记录函数

func ToInteger64

func ToInteger64(s string) (int64, error)

ToInteger64 将代表ip地址、纯数字的string值 都统一转换成int64值

Types

type CountMessage

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

CountMessage .

type Counter

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

Counter .

type FrontServer

type FrontServer struct{}

FrontServer .

func NewFrontServer

func NewFrontServer() *FrontServer

NewFrontServer .

func (*FrontServer) DoMonitorAlive

func (s *FrontServer) DoMonitorAlive(request *utility.HttpRequest, response *utility.HttpResponse, logHandle *utility.Logger)

DoMonitorAlive 监控连接redis是否成功

func (*FrontServer) DoMultiBrowse

func (s *FrontServer) DoMultiBrowse(request *utility.HttpRequest, response *utility.HttpResponse, logHandle *utility.Logger)

DoMultiBrowse 多重浏览访问接口

func (*FrontServer) DoRuleBrowse

func (s *FrontServer) DoRuleBrowse(request *utility.HttpRequest, response *utility.HttpResponse, logHandle *utility.Logger)

DoRuleBrowse 查询访问接口

func (*FrontServer) DoRuleBrowseComplete

func (s *FrontServer) DoRuleBrowseComplete(request *utility.HttpRequest, response *utility.HttpResponse, logHandle *utility.Logger)

DoRuleBrowseComplete 非中断查询接口(可命中、并返回多条策略)

func (*FrontServer) DoRuleUpdate

func (s *FrontServer) DoRuleUpdate(request *utility.HttpRequest, response *utility.HttpResponse, logHandle *utility.Logger)

DoRuleUpdate 更新访问接口

type GroupKey

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

GroupKey 集合 key 类型;满足 KoalaKey interface

type Job

type Job struct {
	ID  string
	Arg string
}

Job .

type JobBuffer

type JobBuffer struct {
	ID string
	// contains filtered or unexported fields
}

JobBuffer .

type JobResult

type JobResult struct {
	ID     string
	Result RetValue
}

JobResult .

type KoalaKey

type KoalaKey interface {
	// contains filtered or unexported methods
}

KoalaKey interface ;用于支持多种 key 类型

type Policy

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

Policy . 策略结构,包含:dicts词表、rule规则、retValue 返回值三种数据; 其中 rule 是主体,dicts、和 retValue 会被 rule引用到

var (
	// GlobalPolicy .全局策略配置
	GlobalPolicy *Policy
	// TempPolicy .临时策略配置(用于策略的动态更新)
	TempPolicy *Policy
)

func NewPolicy

func NewPolicy() *Policy

NewPolicy Policy构造函数,完成各个元素的空间初始化

type RangeKey

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

RangeKey 范围key;一个范围key可以包含多个范围区间

type RetValue

type RetValue struct {
	RetType   int32
	RetCode   int32
	ErrNo     int32
	ErrMsg    string
	StrReason string
	NeedVcode int32
	VcodeLen  int32
	VcodeType int32
	Other     string
	Version   int32
}

RetValue retValue数据类型

type Rule

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

Rule rule类型

func (*Rule) Constructor

func (k *Rule) Constructor(r string) error

Constructor .KoalaRule 的构造器

type Scope

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

Scope 范围 scope 类型,标识一个数值区间,如:>100, 1-9

Jump to

Keyboard shortcuts

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