实现访问日志配置

This commit is contained in:
刘祥超
2020-09-20 11:56:22 +08:00
parent 6a93d17e72
commit ec3dd3a1c8
15 changed files with 1203 additions and 144 deletions

View File

@@ -0,0 +1,74 @@
package serverconfigs
// 代理访问日志配置
type HTTPAccessLogConfig struct {
IsOn bool `yaml:"isOn" json:"isOn"`
Fields []int `yaml:"fields" json:"fields"` // 记录的字段
Status1 bool `yaml:"status1" json:"status1"` // 1xx
Status2 bool `yaml:"status2" json:"status2"` // 2xx
Status3 bool `yaml:"status3" json:"status3"` // 3xx
Status4 bool `yaml:"status4" json:"status4"` // 4xx
Status5 bool `yaml:"status5" json:"status5"` // 5xx
StorageOnly bool `yaml:"storageOnly" json:"storageOnly"` // 是否只输出到存储策略
StoragePolicies []int64 `yaml:"storagePolicies" json:"storagePolicies"` // 存储策略Ids
}
// 获取新对象
func NewHTTPAccessLogConfig() *HTTPAccessLogConfig {
return &HTTPAccessLogConfig{
IsOn: true,
Fields: []int{},
Status1: true,
Status2: true,
Status3: true,
Status4: true,
Status5: true,
}
}
// 校验
func (this *HTTPAccessLogConfig) Init() error {
return nil
}
// 判断是否应该记录
func (this *HTTPAccessLogConfig) Match(status int) bool {
s := status / 100
switch s {
case 1:
if !this.Status1 {
return false
}
case 2:
if !this.Status2 {
return false
}
case 3:
if !this.Status3 {
return false
}
case 4:
if !this.Status4 {
return false
}
case 5:
if !this.Status5 {
return false
}
}
return true
}
// 是否包含某个存储策略
func (this *HTTPAccessLogConfig) ContainsStoragePolicy(storagePolicyId int64) bool {
for _, s := range this.StoragePolicies {
if s == storagePolicyId {
return true
}
}
return false
}

View File

@@ -0,0 +1,45 @@
package serverconfigs
import (
"github.com/iwind/TeaGo/assert"
"testing"
)
func TestHTTPAccessLogConfig_Match(t *testing.T) {
a := assert.NewAssertion(t)
{
accessLog := NewHTTPAccessLogConfig()
a.IsNil(accessLog.Init())
a.IsTrue(accessLog.Match(100))
a.IsTrue(accessLog.Match(200))
a.IsTrue(accessLog.Match(300))
a.IsTrue(accessLog.Match(400))
a.IsTrue(accessLog.Match(500))
}
{
accessLog := NewHTTPAccessLogConfig()
accessLog.Status1 = false
accessLog.Status2 = false
a.IsNil(accessLog.Init())
a.IsFalse(accessLog.Match(100))
a.IsFalse(accessLog.Match(200))
a.IsTrue(accessLog.Match(300))
a.IsTrue(accessLog.Match(400))
a.IsTrue(accessLog.Match(500))
}
{
accessLog := NewHTTPAccessLogConfig()
accessLog.Status3 = false
accessLog.Status4 = false
accessLog.Status5 = false
a.IsNil(accessLog.Init())
a.IsTrue(accessLog.Match(100))
a.IsTrue(accessLog.Match(200))
a.IsFalse(accessLog.Match(300))
a.IsFalse(accessLog.Match(400))
a.IsFalse(accessLog.Match(500))
}
}

View File

@@ -0,0 +1,78 @@
package serverconfigs
import "github.com/iwind/TeaGo/maps"
type HTTPAccessLogField = int
const (
HTTPAccessLogFieldHeader HTTPAccessLogField = 1
HTTPAccessLogFieldSentHeader HTTPAccessLogField = 2
HTTPAccessLogFieldArg HTTPAccessLogField = 3
HTTPAccessLogFieldCookie HTTPAccessLogField = 4
HTTPAccessLogFieldExtend HTTPAccessLogField = 5
HTTPAccessLogFieldReferer HTTPAccessLogField = 6
HTTPAccessLogFieldUserAgent HTTPAccessLogField = 7
HTTPAccessLogFieldRequestBody HTTPAccessLogField = 8
HTTPAccessLogFieldResponseBody HTTPAccessLogField = 9
)
var HTTPAccessLogFieldsCodes = []HTTPAccessLogField{
HTTPAccessLogFieldHeader,
HTTPAccessLogFieldSentHeader,
HTTPAccessLogFieldArg,
HTTPAccessLogFieldCookie,
HTTPAccessLogFieldExtend,
HTTPAccessLogFieldReferer,
HTTPAccessLogFieldUserAgent,
HTTPAccessLogFieldRequestBody,
HTTPAccessLogFieldResponseBody,
}
var HTTPAccessLogDefaultFieldsCodes = []HTTPAccessLogField{
HTTPAccessLogFieldHeader,
HTTPAccessLogFieldSentHeader,
HTTPAccessLogFieldArg,
HTTPAccessLogFieldCookie,
HTTPAccessLogFieldExtend,
HTTPAccessLogFieldReferer,
HTTPAccessLogFieldUserAgent,
}
var HTTPAccessLogFields = []maps.Map{
{
"code": HTTPAccessLogFieldHeader,
"name": "请求Header列表",
},
{
"code": HTTPAccessLogFieldSentHeader,
"name": "响应Header列表",
},
{
"code": HTTPAccessLogFieldArg,
"name": "参数列表",
},
{
"code": HTTPAccessLogFieldCookie,
"name": "Cookie列表",
},
{
"code": HTTPAccessLogFieldExtend,
"name": "位置和浏览器分析",
},
{
"code": HTTPAccessLogFieldReferer,
"name": "请求来源",
},
{
"code": HTTPAccessLogFieldUserAgent,
"name": "终端信息",
},
{
"code": HTTPAccessLogFieldRequestBody,
"name": "请求Body",
},
{
"code": HTTPAccessLogFieldResponseBody,
"name": "响应Body",
},
}

View File

@@ -0,0 +1,112 @@
package serverconfigs
import (
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/configutils"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/logs"
"gopkg.in/yaml.v3"
"io/ioutil"
"os"
"strconv"
)
// 日志存储策略
// 存储在configs/accesslog.storage.$id.conf
type HTTPAccessLogStoragePolicy struct {
Id int64 `yaml:"id" json:"id"`
Name string `yaml:"name" json:"name"`
IsOn bool `yaml:"isOn" json:"isOn"`
Type string `yaml:"type" json:"type"` // 存储类型
Options map[string]interface{} `yaml:"options" json:"options"` // 存储选项
Conds []*shared.RequestCond `yaml:"conds" json:"conds"` // 请求条件
}
// 创建新策略
func NewHTTPAccessLogStoragePolicy() *HTTPAccessLogStoragePolicy {
return &HTTPAccessLogStoragePolicy{
IsOn: true,
}
}
// 从文件中加载策略
func NewAccessLogStoragePolicyFromId(id string) *HTTPAccessLogStoragePolicy {
filename := "accesslog.storage." + id + ".conf"
data, err := ioutil.ReadFile(Tea.ConfigFile(filename))
if err != nil {
logs.Error(err)
return nil
}
policy := NewHTTPAccessLogStoragePolicy()
err = yaml.Unmarshal(data, policy)
if err != nil {
logs.Error(err)
return nil
}
return policy
}
// 校验
func (this *HTTPAccessLogStoragePolicy) Init() error {
// cond
if len(this.Conds) > 0 {
for _, cond := range this.Conds {
err := cond.Init()
if err != nil {
return err
}
}
}
return nil
}
// 保存
func (this *HTTPAccessLogStoragePolicy) Save() error {
shared.Locker.Lock()
defer shared.Locker.Unlock()
data, err := yaml.Marshal(this)
if err != nil {
return err
}
filename := "accesslog.storage." + this.IdString() + ".conf"
return ioutil.WriteFile(Tea.ConfigFile(filename), data, 0666)
}
// 删除
func (this *HTTPAccessLogStoragePolicy) Delete() error {
filename := "accesslog.storage." + this.IdString() + ".conf"
return os.Remove(Tea.ConfigFile(filename))
}
// 匹配关键词
func (this *HTTPAccessLogStoragePolicy) MatchKeyword(keyword string) (matched bool, name string, tags []string) {
if configutils.MatchKeyword(this.Name, keyword) || configutils.MatchKeyword(this.Type, keyword) {
matched = true
name = this.Name
if len(this.Type) > 0 {
tags = []string{"类型:" + this.Type}
}
}
return
}
// 匹配条件
func (this *HTTPAccessLogStoragePolicy) MatchConds(formatter func(string) string) bool {
if len(this.Conds) == 0 {
return true
}
for _, cond := range this.Conds {
if !cond.Match(formatter) {
return false
}
}
return true
}
// 将ID转换为字符串
func (this *HTTPAccessLogStoragePolicy) IdString() string {
return strconv.FormatInt(this.Id, 10)
}

View File

@@ -0,0 +1,80 @@
package serverconfigs
import (
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/files"
"github.com/iwind/TeaGo/logs"
"gopkg.in/yaml.v3"
"io/ioutil"
)
var accessLogStoragePolicyListFilename = "accesslog.storage.list.conf"
// 获取共享的存储策略列表
func SharedHTTPAccessLogStoragePolicyList() *AccessLogStoragePolicyList {
path := Tea.ConfigFile(accessLogStoragePolicyListFilename)
file := files.NewFile(path)
if !file.Exists() {
return &AccessLogStoragePolicyList{}
}
reader, err := file.Reader()
if err != nil {
logs.Error(err)
return &AccessLogStoragePolicyList{}
}
defer reader.Close()
policyList := &AccessLogStoragePolicyList{}
err = reader.ReadYAML(policyList)
if err != nil {
logs.Error(err)
return policyList
}
return policyList
}
// 存储策略列表
type AccessLogStoragePolicyList struct {
Ids []string `yaml:"id" json:"id"`
}
// 添加策略ID
func (this *AccessLogStoragePolicyList) AddId(id string) {
this.Ids = append(this.Ids, id)
}
// 删除策略ID
func (this *AccessLogStoragePolicyList) RemoveId(id string) {
result := []string{}
for _, id2 := range this.Ids {
if id2 == id {
continue
}
result = append(result, id2)
}
this.Ids = result
}
// 保存
func (this *AccessLogStoragePolicyList) Save() error {
data, err := yaml.Marshal(this)
if err != nil {
return err
}
return ioutil.WriteFile(Tea.ConfigFile(accessLogStoragePolicyListFilename), data, 0666)
}
// 查找所有的策略列表
func (this *AccessLogStoragePolicyList) FindAllPolicies() []*HTTPAccessLogStoragePolicy {
shared.Locker.Lock()
defer shared.Locker.Unlock()
result := []*HTTPAccessLogStoragePolicy{}
for _, id := range this.Ids {
policy := NewAccessLogStoragePolicyFromId(id)
if policy != nil {
result = append(result, policy)
}
}
return result
}

View File

@@ -20,10 +20,10 @@ type HTTPCachePolicy struct {
IsOn bool `yaml:"isOn" json:"isOn"` // 是否开启 TODO
Name string `yaml:"name" json:"name"` // 名称
Key string `yaml:"key" json:"key"` // 每个缓存的Key规则里面可以有变量
Key string `yaml:"key" json:"key"` // 每个缓存的Key规则里面可以有变量
Capacity *shared.SizeCapacity `yaml:"capacity" json:"capacity"` // 最大内容容量
Life *shared.TimeDuration `yaml:"life" json:"life"` // 时间
Status []int `yaml:"status" json:"status"` // 缓存的状态码列表
Status []int `yaml:"status" json:"status"` // 缓存的状态码列表
MaxSize *shared.SizeCapacity `yaml:"maxSize" json:"maxSize"` // 能够请求的最大尺寸
SkipResponseCacheControlValues []string `yaml:"skipCacheControlValues" json:"skipCacheControlValues"` // 可以跳过的响应的Cache-Control值
@@ -75,7 +75,7 @@ func NewCachePolicyFromFile(file string) *HTTPCachePolicy {
}
// 校验
func (this *HTTPCachePolicy) Validate() error {
func (this *HTTPCachePolicy) Init() error {
var err error
this.maxSize = this.MaxSize.Bytes()
this.life = this.Life.Duration()
@@ -89,7 +89,7 @@ func (this *HTTPCachePolicy) Validate() error {
// cond
if len(this.Cond) > 0 {
for _, cond := range this.Cond {
err := cond.Validate()
err := cond.Init()
if err != nil {
return err
}

View File

@@ -16,4 +16,5 @@ type HTTPWebConfig struct {
MaxRequestBodySize string `yaml:"maxRequestBodySize" json:"maxRequestBodySize"` // 请求body最大尺寸
RequestHeaders *shared.HTTPHeaderPolicy `yaml:"requestHeaders" json:"requestHeaders"` // 请求Header
ResponseHeaders *shared.HTTPHeaderPolicy `yaml:"responseHeaders" json:"responseHeaders"` // 响应Header`
AccessLog *HTTPAccessLogConfig `yaml:"accessLog" json:"accessLog"` // 访问日志配置
}

View File

@@ -49,7 +49,7 @@ func NewRequestCond() *RequestCond {
}
// 校验配置
func (this *RequestCond) Validate() error {
func (this *RequestCond) Init() error {
this.isInt = RegexpDigitNumber.MatchString(this.Value)
this.isFloat = RegexpFloatNumber.MatchString(this.Value)

View File

@@ -19,7 +19,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorRegexp,
Value: "abc",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(format string) string {
return format
}))
@@ -31,7 +31,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorRegexp,
Value: "/\\w+",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(format string) string {
return format
}))
@@ -43,7 +43,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorRegexp,
Value: `^/article/\d+\.html$`,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(format string) string {
return format
}))
@@ -55,7 +55,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorRegexp,
Value: "[",
}
a.IsNotNil(cond.Validate())
a.IsNotNil(cond.Init())
a.IsFalse(cond.Match(func(format string) string {
return format
}))
@@ -67,7 +67,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorNotRegexp,
Value: "abc",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(format string) string {
return format
}))
@@ -79,7 +79,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorNotRegexp,
Value: "/\\w+",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(format string) string {
return format
}))
@@ -91,7 +91,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorEqInt,
Value: "123",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -103,7 +103,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorEqInt,
Value: "123",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -115,7 +115,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorEqInt,
Value: "abc",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -127,7 +127,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorEqFloat,
Value: "123",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -139,7 +139,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorEqFloat,
Value: "123",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -151,7 +151,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorEqFloat,
Value: "123.12",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -163,7 +163,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorGtFloat,
Value: "1",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -175,7 +175,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorGtFloat,
Value: "125",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -187,7 +187,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorGteFloat,
Value: "125",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -199,7 +199,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorLtFloat,
Value: "127",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -211,7 +211,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorLteFloat,
Value: "127",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -223,7 +223,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorEqString,
Value: "125",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -235,7 +235,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorNeqString,
Value: "125",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -247,7 +247,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorNeqString,
Value: "127",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -259,7 +259,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorHasPrefix,
Value: "/hello",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -271,7 +271,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorHasPrefix,
Value: "/hello2",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -283,7 +283,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorHasSuffix,
Value: "world",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -295,7 +295,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorHasSuffix,
Value: "world/",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -307,7 +307,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorContainsString,
Value: "wo",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -319,7 +319,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorContainsString,
Value: "wr",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -331,7 +331,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorNotContainsString,
Value: "HELLO",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -343,7 +343,7 @@ func TestRequestCond_Compare1(t *testing.T) {
Operator: RequestCondOperatorNotContainsString,
Value: "hello",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -359,7 +359,7 @@ func TestRequestCond_IP(t *testing.T) {
Operator: RequestCondOperatorEqIP,
Value: "hello",
}
a.IsNotNil(cond.Validate())
a.IsNotNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -371,7 +371,7 @@ func TestRequestCond_IP(t *testing.T) {
Operator: RequestCondOperatorEqIP,
Value: "hello",
}
a.IsNotNil(cond.Validate())
a.IsNotNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -383,7 +383,7 @@ func TestRequestCond_IP(t *testing.T) {
Operator: RequestCondOperatorEqIP,
Value: "192.168.1.100",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -395,7 +395,7 @@ func TestRequestCond_IP(t *testing.T) {
Operator: RequestCondOperatorGtIP,
Value: "192.168.1.90",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -407,7 +407,7 @@ func TestRequestCond_IP(t *testing.T) {
Operator: RequestCondOperatorGteIP,
Value: "192.168.1.90",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -419,7 +419,7 @@ func TestRequestCond_IP(t *testing.T) {
Operator: RequestCondOperatorLtIP,
Value: "192.168.1.90",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -431,7 +431,7 @@ func TestRequestCond_IP(t *testing.T) {
Operator: RequestCondOperatorLteIP,
Value: "192.168.1.90",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -443,7 +443,7 @@ func TestRequestCond_IP(t *testing.T) {
Operator: RequestCondOperatorIPRange,
Value: "192.168.0.90,",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -455,7 +455,7 @@ func TestRequestCond_IP(t *testing.T) {
Operator: RequestCondOperatorIPRange,
Value: "192.168.0.90,192.168.1.100",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -467,7 +467,7 @@ func TestRequestCond_IP(t *testing.T) {
Operator: RequestCondOperatorIPRange,
Value: ",192.168.1.100",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -479,7 +479,7 @@ func TestRequestCond_IP(t *testing.T) {
Operator: RequestCondOperatorIPRange,
Value: "192.168.0.90,192.168.1.99",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -491,7 +491,7 @@ func TestRequestCond_IP(t *testing.T) {
Operator: RequestCondOperatorIPRange,
Value: "192.168.0.90/24",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -503,7 +503,7 @@ func TestRequestCond_IP(t *testing.T) {
Operator: RequestCondOperatorIPRange,
Value: "192.168.0.90/18",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -515,7 +515,7 @@ func TestRequestCond_IP(t *testing.T) {
Operator: RequestCondOperatorIPRange,
Value: "a/18",
}
a.IsNotNil(cond.Validate())
a.IsNotNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -527,7 +527,7 @@ func TestRequestCond_IP(t *testing.T) {
Operator: RequestCondOperatorIPMod10,
Value: "6",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -539,7 +539,7 @@ func TestRequestCond_IP(t *testing.T) {
Operator: RequestCondOperatorIPMod100,
Value: "76",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -551,7 +551,7 @@ func TestRequestCond_IP(t *testing.T) {
Operator: RequestCondOperatorIPMod,
Value: "10,6",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -605,7 +605,7 @@ func TestRequestCond_In(t *testing.T) {
Operator: RequestCondOperatorIn,
Value: `a`,
}
a.IsNotNil(cond.Validate())
a.IsNotNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -617,7 +617,7 @@ func TestRequestCond_In(t *testing.T) {
Operator: RequestCondOperatorIn,
Value: `["a", "b"]`,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -629,7 +629,7 @@ func TestRequestCond_In(t *testing.T) {
Operator: RequestCondOperatorNotIn,
Value: `["a", "b"]`,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -641,7 +641,7 @@ func TestRequestCond_In(t *testing.T) {
Operator: RequestCondOperatorNotIn,
Value: `["a", "b"]`,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -657,7 +657,7 @@ func TestRequestCond_File(t *testing.T) {
Operator: RequestCondOperatorFileExt,
Value: `["jpeg", "jpg", "png"]`,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -669,7 +669,7 @@ func TestRequestCond_File(t *testing.T) {
Operator: RequestCondOperatorFileExt,
Value: `["jpeg", "jpg", "png"]`,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -681,7 +681,7 @@ func TestRequestCond_File(t *testing.T) {
Operator: RequestCondOperatorFileExt,
Value: `["jpeg", "jpg", "png"]`,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -692,7 +692,7 @@ func TestRequestCond_File(t *testing.T) {
Param: "a.png",
Operator: RequestCondOperatorFileExist,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -703,7 +703,7 @@ func TestRequestCond_File(t *testing.T) {
Param: Tea.Root + "/README.md",
Operator: RequestCondOperatorFileExist,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -714,7 +714,7 @@ func TestRequestCond_File(t *testing.T) {
Param: Tea.Root + "/README.md?v=1",
Operator: RequestCondOperatorFileExist,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -725,7 +725,7 @@ func TestRequestCond_File(t *testing.T) {
Param: Tea.Root,
Operator: RequestCondOperatorFileExist,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -736,7 +736,7 @@ func TestRequestCond_File(t *testing.T) {
Param: Tea.Root,
Operator: RequestCondOperatorFileExist,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -747,7 +747,7 @@ func TestRequestCond_File(t *testing.T) {
Param: "a.png",
Operator: RequestCondOperatorFileNotExist,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -758,7 +758,7 @@ func TestRequestCond_File(t *testing.T) {
Param: Tea.Root + "/README.md",
Operator: RequestCondOperatorFileNotExist,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -774,7 +774,7 @@ func TestRequestCond_MimeType(t *testing.T) {
Operator: RequestCondOperatorFileMimeType,
Value: `["text/html"]`,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -786,7 +786,7 @@ func TestRequestCond_MimeType(t *testing.T) {
Operator: RequestCondOperatorFileMimeType,
Value: `["text/*"]`,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -798,7 +798,7 @@ func TestRequestCond_MimeType(t *testing.T) {
Operator: RequestCondOperatorFileMimeType,
Value: `["image/*"]`,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -810,7 +810,7 @@ func TestRequestCond_MimeType(t *testing.T) {
Operator: RequestCondOperatorFileMimeType,
Value: `["text/html", "image/jpeg", "image/png"]`,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -826,7 +826,7 @@ func TestRequestCond_Version(t *testing.T) {
Operator: RequestCondOperatorVersionRange,
Value: `1.0,1.1`,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -838,7 +838,7 @@ func TestRequestCond_Version(t *testing.T) {
Operator: RequestCondOperatorVersionRange,
Value: `1.0,`,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -850,7 +850,7 @@ func TestRequestCond_Version(t *testing.T) {
Operator: RequestCondOperatorVersionRange,
Value: `,1.1`,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -862,7 +862,7 @@ func TestRequestCond_Version(t *testing.T) {
Operator: RequestCondOperatorVersionRange,
Value: `1.0,1.1`,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -874,7 +874,7 @@ func TestRequestCond_Version(t *testing.T) {
Operator: RequestCondOperatorVersionRange,
Value: `1.0`,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -886,7 +886,7 @@ func TestRequestCond_Version(t *testing.T) {
Operator: RequestCondOperatorVersionRange,
Value: `1.0`,
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -908,7 +908,7 @@ func TestRequestCond_Mod(t *testing.T) {
Operator: RequestCondOperatorMod,
Value: "1",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -920,7 +920,7 @@ func TestRequestCond_Mod(t *testing.T) {
Operator: RequestCondOperatorMod,
Value: "2",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(source string) string {
return source
}))
@@ -932,7 +932,7 @@ func TestRequestCond_Mod(t *testing.T) {
Operator: RequestCondOperatorMod,
Value: "3",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -944,7 +944,7 @@ func TestRequestCond_Mod(t *testing.T) {
Operator: RequestCondOperatorMod,
Value: "11,1",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -956,7 +956,7 @@ func TestRequestCond_Mod(t *testing.T) {
Operator: RequestCondOperatorMod,
Value: "11,3",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -968,7 +968,7 @@ func TestRequestCond_Mod(t *testing.T) {
Operator: RequestCondOperatorMod,
Value: "2,0",
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -980,7 +980,7 @@ func TestRequestCond_Mod(t *testing.T) {
Operator: RequestCondOperatorMod10,
Value: fmt.Sprintf("%d", i%10),
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))
@@ -992,7 +992,7 @@ func TestRequestCond_Mod(t *testing.T) {
Operator: RequestCondOperatorMod100,
Value: fmt.Sprintf("%d", i%100),
}
a.IsNil(cond.Validate())
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(source string) string {
return source
}))