shared

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2019 License: MIT Imports: 12 Imported by: 21

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultSkippedResponseCacheControlValues = []string{"private", "no-cache", "no-store"}
View Source
var Locker = new(FileLocker)

Functions

This section is empty.

Types

type AccessConfig

type AccessConfig struct {
	On      bool            `yaml:"on" json:"on"`           // 是否开启
	AllowOn bool            `yaml:"allowOn" json:"allowOn"` // 白名单是否开启
	DenyOn  bool            `yaml:"denyOn" json:"denyOn"`   // 黑名单是否开启
	Allow   []*ClientConfig `yaml:"allow" json:"allow"`     // 允许的IP
	Deny    []*ClientConfig `yaml:"deny" json:"deny"`       // 禁止的IP
}

访问控制

func (*AccessConfig) AddAllow

func (this *AccessConfig) AddAllow(client *ClientConfig)

添加允许的客户端

func (*AccessConfig) AddDeny

func (this *AccessConfig) AddDeny(client *ClientConfig)

添加禁用的客户端

func (*AccessConfig) Validate

func (this *AccessConfig) Validate() error

校验

type AccessPolicy

type AccessPolicy struct {

	// 流量控制
	Traffic struct {
		On    bool `yaml:"on" json:"on"` // 是否开启
		Total struct {
			On    bool  `yaml:"on" json:"on"`       // 是否开启
			Total int64 `yaml:"total" json:"total"` // 总量
			Used  int64 `yaml:"used" json:"used"`   // 已使用量
		} `yaml:"total" json:"total"` // 总量控制
		Second struct {
			On       bool  `yaml:"on" json:"on"`             // 是否开启
			Total    int64 `yaml:"total" json:"total"`       // 总量
			Duration int64 `yaml:"duration" json:"duration"` // 时间长度
			FromTime int64 `yaml:"fromTime" json:"fromTime"` // 开始时间,也是结束时间
			Used     int64 `yaml:"used" json:"used"`         // 已使用量
		} `yaml:"second" json:"second"`
		Minute struct {
			On       bool  `yaml:"on" json:"on"`             // 是否开启
			Total    int64 `yaml:"total" json:"total"`       // 总量
			Duration int64 `yaml:"duration" json:"duration"` // 时间长度
			FromTime int64 `yaml:"fromTime" json:"fromTime"` // 开始时间
			ToTime   int64 `yaml:"toTime" json:"toTime"`     // 结束时间
			Used     int64 `yaml:"used" json:"used"`         // 已使用量
		} `yaml:"minute" json:"minute"`
		Hour struct {
			On       bool  `yaml:"on" json:"on"`             // 是否开启
			Total    int64 `yaml:"total" json:"total"`       // 总量
			Duration int64 `yaml:"duration" json:"duration"` // 时间长度
			FromTime int64 `yaml:"fromTime" json:"fromTime"` // 开始时间
			ToTime   int64 `yaml:"toTime" json:"toTime"`     // 结束时间
			Used     int64 `yaml:"used" json:"used"`         // 已使用量
		} `yaml:"hour" json:"hour"`
		Day struct {
			On       bool  `yaml:"on" json:"on"`             // 是否开启
			Total    int64 `yaml:"total" json:"total"`       // 总量
			Duration int64 `yaml:"duration" json:"duration"` // 时间长度
			FromTime int64 `yaml:"fromTime" json:"fromTime"` // 开始时间
			ToTime   int64 `yaml:"toTime" json:"toTime"`     // 结束时间
			Used     int64 `yaml:"used" json:"used"`         // 已使用量
		} `yaml:"day" json:"day"`
		Month struct {
			On       bool  `yaml:"on" json:"on"`             // 是否开启
			Total    int64 `yaml:"total" json:"total"`       // 总量
			Duration int64 `yaml:"duration" json:"duration"` // 时间长度
			FromTime int64 `yaml:"fromTime" json:"fromTime"` // 开始时间
			ToTime   int64 `yaml:"toTime" json:"toTime"`     // 结束时间
			Used     int64 `yaml:"used" json:"used"`         // 已使用量
		} `yaml:"month" json:"month"`
	} `yaml:"traffic" json:"traffic"` // 流量控制

	// 访问控制
	Access AccessConfig `yaml:"access" json:"access"` // 访问控制
	// contains filtered or unexported fields
}

API控制策略

func NewAccessPolicy

func NewAccessPolicy() *AccessPolicy

获取新对象

func (*AccessPolicy) AllowAccess

func (this *AccessPolicy) AllowAccess(ip string) bool

检查权限

func (*AccessPolicy) AllowTraffic

func (this *AccessPolicy) AllowTraffic() (reason string, allowed bool)

检查流量

func (*AccessPolicy) FinishChange

func (this *AccessPolicy) FinishChange()

设置已完成改变

func (*AccessPolicy) IncreaseTraffic

func (this *AccessPolicy) IncreaseTraffic()

增加流量

func (*AccessPolicy) IsChanged

func (this *AccessPolicy) IsChanged() bool

判断是否改变

func (*AccessPolicy) Validate

func (this *AccessPolicy) Validate() error

校验

type CachePolicy

type CachePolicy struct {
	Filename string `yaml:"filename" json:"filename"` // 文件名
	Id       string `yaml:"id" json:"id"`
	On       bool   `yaml:"on" json:"on"`     // 是否开启 TODO
	Name     string `yaml:"name" json:"name"` // 名称

	Key      string `yaml:"key" json:"key"`           // 每个缓存的Key规则,里面可以有变量
	Capacity string `yaml:"capacity" json:"capacity"` // 最大内容容量
	Life     string `yaml:"life" json:"life"`         // 时间
	Status   []int  `yaml:"status" json:"status"`     // 缓存的状态码列表
	MaxSize  string `yaml:"maxSize" json:"maxSize"`   // 能够请求的最大尺寸

	SkipResponseCacheControlValues []string `yaml:"skipCacheControlValues" json:"skipCacheControlValues"`     // 可以跳过的响应的Cache-Control值
	SkipResponseSetCookie          bool     `yaml:"skipSetCookie" json:"skipSetCookie"`                       // 是否跳过响应的Set-Cookie Header
	EnableRequestCachePragma       bool     `yaml:"enableRequestCachePragma" json:"enableRequestCachePragma"` // 是否支持客户端的Pragma: no-cache

	Type    string                 `yaml:"type" json:"type"`       // 类型
	Options map[string]interface{} `yaml:"options" json:"options"` // 选项
	// contains filtered or unexported fields
}

缓存策略配置

func NewCachePolicy

func NewCachePolicy() *CachePolicy

获取新对象

func NewCachePolicyFromFile

func NewCachePolicyFromFile(file string) *CachePolicy

从文件中读取缓存策略

func (*CachePolicy) CapacitySize

func (this *CachePolicy) CapacitySize() float64

容量

func (*CachePolicy) ContainsCacheControl added in v0.1.5

func (this *CachePolicy) ContainsCacheControl(value string) bool

是否包含某个Cache-Control值

func (*CachePolicy) Delete

func (this *CachePolicy) Delete() error

删除

func (*CachePolicy) LifeDuration

func (this *CachePolicy) LifeDuration() time.Duration

生命周期

func (*CachePolicy) MaxDataSize

func (this *CachePolicy) MaxDataSize() float64

最大数据尺寸

func (*CachePolicy) Save

func (this *CachePolicy) Save() error

保存

func (*CachePolicy) Validate

func (this *CachePolicy) Validate() error

校验

type ClientConfig

type ClientConfig struct {
	Id          string `yaml:"id" json:"id"`                   // ID
	On          bool   `yaml:"on" json:"on"`                   // 是否开启
	IP          string `yaml:"ip" json:"ip"`                   // IP
	Description string `yaml:"description" json:"description"` // 描述
	// contains filtered or unexported fields
}

客户端配置

func NewClientConfig

func NewClientConfig() *ClientConfig

取得新配置对象

func (*ClientConfig) Match

func (this *ClientConfig) Match(ip string) bool

判断是否匹配某个IP

func (*ClientConfig) Validate

func (this *ClientConfig) Validate() error

校验

type FileLocker added in v0.1.4

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

global file modify locker

func (*FileLocker) Lock added in v0.1.4

func (this *FileLocker) Lock()

lock

func (*FileLocker) ReadUnlock added in v0.1.4

func (this *FileLocker) ReadUnlock()

unlock for read

func (*FileLocker) WriteUnlock added in v0.1.4

func (this *FileLocker) WriteUnlock()

unlock for write

func (*FileLocker) WriteUnlockNotify added in v0.1.4

func (this *FileLocker) WriteUnlockNotify()

unlock for write and notify

type HeaderConfig

type HeaderConfig struct {
	On     bool   `yaml:"on" json:"on"`         // 是否开启
	Id     string `yaml:"id" json:"id"`         // ID
	Name   string `yaml:"name" json:"name"`     // Name
	Value  string `yaml:"value" json:"value"`   // Value
	Always bool   `yaml:"always" json:"always"` // 是否忽略状态码
	Status []int  `yaml:"status" json:"status"` // 支持的状态码
	// contains filtered or unexported fields
}

头部信息定义

func NewHeaderConfig

func NewHeaderConfig() *HeaderConfig

获取新Header对象

func (*HeaderConfig) HasVariables added in v0.1.5

func (this *HeaderConfig) HasVariables() bool

是否有变量

func (*HeaderConfig) Match

func (this *HeaderConfig) Match(statusCode int) bool

判断是否匹配状态码

func (*HeaderConfig) Validate

func (this *HeaderConfig) Validate() error

校验

type HeaderList

type HeaderList struct {
	// 添加的响应Headers
	Headers []*HeaderConfig `yaml:"headers" json:"headers"`

	// 忽略的响应Headers
	IgnoreHeaders []string `yaml:"ignoreHeaders" json:"ignoreHeaders"`

	// 请求Headers
	RequestHeaders []*HeaderConfig `yaml:"requestHeaders" json:"requestHeaders"`
	// contains filtered or unexported fields
}

HeaderList定义

func (*HeaderList) AddIgnoreResponseHeader added in v0.1.5

func (this *HeaderList) AddIgnoreResponseHeader(name string)

添加IgnoreHeader

func (*HeaderList) AddRequestHeader added in v0.1.5

func (this *HeaderList) AddRequestHeader(header *HeaderConfig)

添加请求Header

func (*HeaderList) AddResponseHeader added in v0.1.5

func (this *HeaderList) AddResponseHeader(header *HeaderConfig)

添加Header

func (*HeaderList) AllIgnoreResponseHeaders added in v0.1.5

func (this *HeaderList) AllIgnoreResponseHeaders() []string

取得所有的IgnoreHeader

func (*HeaderList) AllRequestHeaders added in v0.1.5

func (this *HeaderList) AllRequestHeaders() []*HeaderConfig

取得所有的请求Header

func (*HeaderList) AllResponseHeaders added in v0.1.5

func (this *HeaderList) AllResponseHeaders() []*HeaderConfig

取得所有的Header

func (*HeaderList) ContainsIgnoreResponseHeader added in v0.1.5

func (this *HeaderList) ContainsIgnoreResponseHeader(name string) bool

判断是否包含IgnoreHeader

func (*HeaderList) ContainsResponseHeader added in v0.1.5

func (this *HeaderList) ContainsResponseHeader(name string) bool

判断是否包含Header

func (*HeaderList) FindRequestHeader added in v0.1.5

func (this *HeaderList) FindRequestHeader(headerId string) *HeaderConfig

查找请求Header

func (*HeaderList) FindResponseHeader added in v0.1.5

func (this *HeaderList) FindResponseHeader(headerId string) *HeaderConfig

查找Header

func (*HeaderList) HasIgnoreHeaders added in v0.1.6

func (this *HeaderList) HasIgnoreHeaders() bool

判断是否有Ignore Headers

func (*HeaderList) HasRequestHeaders added in v0.1.5

func (this *HeaderList) HasRequestHeaders() bool

判断是否有请求Header

func (*HeaderList) HasResponseHeaders added in v0.1.5

func (this *HeaderList) HasResponseHeaders() bool

是否有Headers

func (*HeaderList) RemoveIgnoreResponseHeader added in v0.1.5

func (this *HeaderList) RemoveIgnoreResponseHeader(name string)

移除IgnoreHeader

func (*HeaderList) RemoveRequestHeader added in v0.1.5

func (this *HeaderList) RemoveRequestHeader(headerId string)

移除请求Header

func (*HeaderList) RemoveResponseHeader added in v0.1.5

func (this *HeaderList) RemoveResponseHeader(headerId string)

移除Header

func (*HeaderList) UpdateIgnoreResponseHeader added in v0.1.5

func (this *HeaderList) UpdateIgnoreResponseHeader(oldName string, newName string)

修改IgnoreHeader

func (*HeaderList) UppercaseIgnoreHeaders added in v0.1.6

func (this *HeaderList) UppercaseIgnoreHeaders() []string

查找大写的Ignore Headers

func (*HeaderList) ValidateHeaders

func (this *HeaderList) ValidateHeaders() error

校验

type HeaderListInterface

type HeaderListInterface interface {
	// 校验
	ValidateHeaders() error

	// 取得所有的IgnoreHeader
	AllIgnoreResponseHeaders() []string

	// 添加IgnoreHeader
	AddIgnoreResponseHeader(name string)

	// 判断是否包含IgnoreHeader
	ContainsIgnoreResponseHeader(name string) bool

	// 移除IgnoreHeader
	RemoveIgnoreResponseHeader(name string)

	// 修改IgnoreHeader
	UpdateIgnoreResponseHeader(oldName string, newName string)

	// 取得所有的Header
	AllResponseHeaders() []*HeaderConfig

	// 添加Header
	AddResponseHeader(header *HeaderConfig)

	// 判断是否包含Header
	ContainsResponseHeader(name string) bool

	// 查找Header
	FindResponseHeader(headerId string) *HeaderConfig

	// 移除Header
	RemoveResponseHeader(headerId string)

	// 取得所有的请求Header
	AllRequestHeaders() []*HeaderConfig

	// 添加请求Header
	AddRequestHeader(header *HeaderConfig)

	// 查找请求Header
	FindRequestHeader(headerId string) *HeaderConfig

	// 移除请求Header
	RemoveRequestHeader(headerId string)
}

HeaderList相关操作接口

type Pair added in v0.1.2

type Pair struct {
	Name  string `yaml:"name" json:"name"`   // 变量名
	Value string `yaml:"value" json:"value"` // 变量值
}

键值对

type RequestCall added in v0.1.2

type RequestCall struct {
	Formatter         func(source string) string
	Request           *http.Request
	ResponseCallbacks []func(resp http.ResponseWriter)
	Options           maps.Map
}

请求调用

func NewRequestCall added in v0.1.2

func NewRequestCall() *RequestCall

获取新对象

func (*RequestCall) AddResponseCall added in v0.1.2

func (this *RequestCall) AddResponseCall(callback func(resp http.ResponseWriter))

添加响应回调

func (*RequestCall) CallResponseCallbacks added in v0.1.2

func (this *RequestCall) CallResponseCallbacks(resp http.ResponseWriter)

执行响应回调

func (*RequestCall) Reset added in v0.1.6

func (this *RequestCall) Reset()

重置

type Variable added in v0.1.2

type Variable struct {
	Name  string `yaml:"name" json:"name"`   // 变量名
	Value string `yaml:"value" json:"value"` // 变量值
}

变量

func NewVariable added in v0.1.2

func NewVariable(name string, value string) *Variable

创建新变量

Jump to

Keyboard shortcuts

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