Documentation
¶
Overview ¶
resolv.nginx 包,该包包含了bifrost.pkg.resolv.nginx项目最基础的上下文相关对象,及相关方法及函数 创建者: ClessLi 创建时间:2020-1-17 11:14:15
Index ¶
- Constants
- Variables
- func Backup(config *Config, name string, saveTime, bakCycle int, backupDir ...string) (bakPath string, err error)
- func Delete(config *Config) (err error)
- func GetPort(ctx Context) int
- func SortByOrders(slice *[]Parser, orders ...Order)
- func SortInsertInt(slice []int, ints ...int) []int
- func SortInsertUniqInt(slice []int, ints ...int) []int
- func StripSpace(s string) string
- type BasicContext
- func (c *BasicContext) Add(pType parserType, values ...string) error
- func (c *BasicContext) AddByParser(contents ...Parser)
- func (c *BasicContext) Insert(indexParser Parser, pType parserType, values ...string) error
- func (c *BasicContext) InsertByParser(indexParser Parser, contents ...Parser) error
- func (c *BasicContext) List() (caches Caches, err error)
- func (c *BasicContext) Modify(indexParser Parser, pType parserType, values ...string) error
- func (c *BasicContext) ModifyByParser(indexParser, content Parser) error
- func (c *BasicContext) Params() (parsers []Parser)
- func (c *BasicContext) Query(pType parserType, isRec bool, values ...string) Parser
- func (c *BasicContext) QueryAll(pType parserType, isRec bool, values ...string) []Parser
- func (c *BasicContext) Remove(pType parserType, values ...string) error
- func (c *BasicContext) RemoveByParser(contents ...Parser)
- func (c *BasicContext) Server() *Server
- func (c *BasicContext) Servers() []Parser
- func (c BasicContext) String() []string
- type Caches
- type Comment
- func (cmt *Comment) BitLen(_ Order) int
- func (cmt *Comment) BitSize(_ Order, _ int) byte
- func (cmt *Comment) Query(pType parserType, isRec bool, values ...string) Parser
- func (cmt *Comment) QueryAll(pType parserType, isRec bool, values ...string) []Parser
- func (cmt *Comment) QueryAllByKeywords(kw Keywords) (parsers []Parser)
- func (cmt *Comment) QueryByKeywords(kw Keywords) (parser Parser)
- func (cmt *Comment) Size(_ Order) int
- func (cmt Comment) String() []string
- type Config
- func (c *Config) BitLen(_ Order) int
- func (c *Config) BitSize(_ Order, _ int) byte
- func (c *Config) List() (caches Caches, err error)
- func (c *Config) QueryAllByKeywords(kw Keywords) (parsers []Parser)
- func (c *Config) QueryByKeywords(kw Keywords) (parser Parser)
- func (c *Config) Save() (Caches, error)
- func (c *Config) Size(_ Order) int
- func (c Config) String() []string
- type Context
- type Events
- type Geo
- type Http
- type If
- type Include
- func (i *Include) Add(pType parserType, values ...string) error
- func (i *Include) AddByParser(contents ...Parser)
- func (i *Include) AddConfig(configs ...Parser) error
- func (i *Include) BitLen(_ Order) int
- func (i *Include) BitSize(_ Order, _ int) byte
- func (i *Include) Insert(indexParser Parser, pType parserType, values ...string) error
- func (i *Include) InsertByParser(indexParser Parser, contents ...Parser) error
- func (i *Include) Modify(indexParser Parser, pType parserType, values ...string) error
- func (i *Include) ModifyByParser(indexParser Parser, content Parser) error
- func (i *Include) Params() (parsers []Parser)
- func (i *Include) Query(pType parserType, isRec bool, values ...string) Parser
- func (i *Include) QueryAll(pType parserType, isRec bool, values ...string) []Parser
- func (i *Include) QueryAllByKeywords(kw Keywords) (parsers []Parser)
- func (i *Include) QueryByKeywords(kw Keywords) Parser
- func (i *Include) Remove(pType parserType, values ...string) error
- func (i *Include) RemoveByParser(contents ...Parser)
- func (i *Include) Size(_ Order) int
- func (i Include) String() []string
- type Key
- func (k *Key) BitLen(_ Order) int
- func (k *Key) BitSize(_ Order, _ int) byte
- func (k *Key) Query(pType parserType, isRec bool, values ...string) Parser
- func (k *Key) QueryAll(pType parserType, isRec bool, values ...string) []Parser
- func (k *Key) QueryAllByKeywords(kw Keywords) (parsers []Parser)
- func (k *Key) QueryByKeywords(kw Keywords) (parser Parser)
- func (k *Key) Size(_ Order) int
- func (k Key) String() []string
- type Keyword
- type Keywords
- type LimitExcept
- type Location
- type Map
- type Order
- type Parser
- type Server
- type Stream
- type Types
- type Upstream
Constants ¶
View Source
const ( DoubleQuotes = `\s*"[^"]*"` SingleQuotes = `\s*'[^']*'` Normal = `\s*[^;\s]*` S1 = DoubleQuotes + `|` + SingleQuotes + `|` + Normal S = `^\s*(` + S1 + `)\s*((?:` + S1 + `)+);` TypeConfig parserType = "config" TypeEvents parserType = "events" TypeGeo parserType = "geo" TypeHttp parserType = "http" TypeIf parserType = "if" TypeInclude parserType = "include" TypeKey parserType = "key" TypeLimitExcept parserType = "limit_except" TypeLocation parserType = "location" TypeMap parserType = "map" TypeServer parserType = "server" TypeStream parserType = "stream" TypeTypes parserType = "types" TypeUpstream parserType = "upstream" TypeComment parserType = "comment" )
Variables ¶
View Source
var ( //system vars TZ = time.Local // regexp RegEndWithCR = regexp.MustCompile("}\n+$") RegEventsHead = regexp.MustCompile(`^\s*events\s*{`) RegHttpHead = regexp.MustCompile(`^\s*http\s*{`) RegStreamHead = regexp.MustCompile(`^\s*stream\s*{`) RegServerHead = regexp.MustCompile(`^\s*server\s*{`) RegLocationHead = regexp.MustCompile(`^\s*location\s*([^;]*?)\s*{`) RegIfHead = regexp.MustCompile(`^\s*if\s*([^;]*?)\s*{`) RegUpstreamHead = regexp.MustCompile(`^\s*upstream\s*([^;]*?)\s*{`) RegGeoHead = regexp.MustCompile(`^\s*geo\s*([^;]*?)\s*{`) RegMapHead = regexp.MustCompile(`^\s*map\s*([^;]*?)\s*{`) RegLimitExceptHead = regexp.MustCompile(`^\s*limit_except\s*([^;]*?)\s*{`) RegTypesHead = regexp.MustCompile(`^\s*types\s*{`) RegContextEnd = regexp.MustCompile(`^\s*}`) RegCommentHead = regexp.MustCompile(`^(\s*)#+[ \r\t\f]*(.*?)\n`) RegKeyValue = regexp.MustCompile(S) RegKey = regexp.MustCompile(`^\s*(\S+);`) RegPortValue = regexp.MustCompile(`^(\d+)\s*\S*$`) KeywordHTTP = NewKeyWords(TypeHttp, "", "", false, true) KeywordStream = NewKeyWords(TypeStream, "", "", false, true) KeywordSvrName = NewKeyWords(TypeKey, `server_name`, `*`, false, true) KeywordPort = NewKeyWords(TypeKey, `^listen$`, `.*`, true, true) // errors ParserTypeError = fmt.Errorf("invalid parserType") ParserControlNoParamError = fmt.Errorf("no valid param has been inputed") ParserControlParamsError = fmt.Errorf("unkown param has been inputed") ParserControlIndexNotFoundError = fmt.Errorf("index not found") NoBackupRequired = fmt.Errorf("no backup required") NoReloadRequired = fmt.Errorf("no reload required") IsInCaches = fmt.Errorf("cache already exists") IsNotInCaches = fmt.Errorf("cache is not exists") )
View Source
var INDENT = " "
Functions ¶
func Backup ¶
func Backup(config *Config, name string, saveTime, bakCycle int, backupDir ...string) (bakPath string, err error)
Backup, 文件归档函数
参数:
config: nginx配置文件对象指针 name: 归档文件前缀名 saveTime: 归档文件保存时间,单位天 bakCycle: 归档操作周期,单位天 backupDir: 可选参数,备份目录
返回值:
bakPath: 归档文件路径 err: 错误
func SortByOrders ¶
func SortInsertInt ¶
func SortInsertUniqInt ¶
func StripSpace ¶
Types ¶
type BasicContext ¶
type BasicContext struct { Name parserType `json:"-"` Value string `json:"value,omitempty"` Children []Parser `json:"param,omitempty"` }
BasicContext, 上下文基础对象,定义了上下文类型的基本属性及基础方法
func (*BasicContext) Add ¶
func (c *BasicContext) Add(pType parserType, values ...string) error
func (*BasicContext) AddByParser ¶
func (c *BasicContext) AddByParser(contents ...Parser)
AddByParser, BasicContext 类新增子对象的方法, Context.AddByParser(...Parser) 的实现
func (*BasicContext) Insert ¶
func (c *BasicContext) Insert(indexParser Parser, pType parserType, values ...string) error
func (*BasicContext) InsertByParser ¶
func (c *BasicContext) InsertByParser(indexParser Parser, contents ...Parser) error
InsertByParser, BasicContext 类插入对象的方法, Context.InsertByParser(indexParser Parser, insertParsers ...Parser) error 的实现
参数:
indexParser: 基准索引子对象 insertParsers: 待插入子对象集
返回值:
错误
func (*BasicContext) List ¶
func (c *BasicContext) List() (caches Caches, err error)
func (*BasicContext) Modify ¶
func (c *BasicContext) Modify(indexParser Parser, pType parserType, values ...string) error
func (*BasicContext) ModifyByParser ¶
func (c *BasicContext) ModifyByParser(indexParser, content Parser) error
ModifyByParser, BasicContext 类修改子对象的方法, Context.ModifyByParser(int, Parser) error 的实现
func (*BasicContext) Params ¶
func (c *BasicContext) Params() (parsers []Parser)
func (*BasicContext) Query ¶
func (c *BasicContext) Query(pType parserType, isRec bool, values ...string) Parser
func (*BasicContext) QueryAll ¶
func (c *BasicContext) QueryAll(pType parserType, isRec bool, values ...string) []Parser
func (*BasicContext) Remove ¶
func (c *BasicContext) Remove(pType parserType, values ...string) error
func (*BasicContext) RemoveByParser ¶
func (c *BasicContext) RemoveByParser(contents ...Parser)
RemoveByParser, BasicContext 类删除子对象的方法, Context.RemoveByParser(...Parser) 的实现
func (*BasicContext) Server ¶
func (c *BasicContext) Server() *Server
func (*BasicContext) Servers ¶
func (c *BasicContext) Servers() []Parser
func (BasicContext) String ¶
func (c BasicContext) String() []string
type Comment ¶
func NewComment ¶
func (*Comment) QueryAllByKeywords ¶
func (*Comment) QueryByKeywords ¶
type Config ¶
type Config struct {
BasicContext `json:"config"`
}
func (*Config) QueryAllByKeywords ¶
func (*Config) QueryByKeywords ¶
type Context ¶
type Context interface { Parser Insert(indexParser Parser, pType parserType, values ...string) error InsertByParser(indexParser Parser, contents ...Parser) error Add(parserType, ...string) error AddByParser(...Parser) Remove(parserType, ...string) error RemoveByParser(...Parser) Modify(indexParser Parser, pType parserType, values ...string) error ModifyByParser(Parser, Parser) error Servers() []Parser Server() *Server Params() []Parser List() (Caches, error) // contains filtered or unexported methods }
Context, 上下文接口对象,定义了上下文接口需实现的增、删、改等方法
type Events ¶
type Events struct {
BasicContext `json:"events"`
}
func (*Events) QueryAllByKeywords ¶
func (*Events) QueryByKeywords ¶
type Geo ¶
type Geo struct {
BasicContext `json:"geo"`
}
func (*Geo) QueryAllByKeywords ¶
func (*Geo) QueryByKeywords ¶
type Http ¶
type Http struct {
BasicContext `json:"http"`
}
func (*Http) QueryAllByKeywords ¶
func (*Http) QueryByKeywords ¶
type If ¶
type If struct {
BasicContext `json:"if"`
}
func (*If) QueryAllByKeywords ¶
func (*If) QueryByKeywords ¶
type Include ¶
type Include struct { BasicContext `json:"include"` Key *Key `json:"tags"` Comment *Comment `json:"comments"` ConfPWD string `json:"conf_pwd"` }
func (*Include) AddByParser ¶
func (*Include) InsertByParser ¶
func (*Include) ModifyByParser ¶
func (*Include) QueryAllByKeywords ¶
func (*Include) QueryByKeywords ¶
func (*Include) RemoveByParser ¶
type Keywords ¶
func NewKeyWords ¶
type LimitExcept ¶
type LimitExcept struct {
BasicContext `json:"limit_except"`
}
func NewLimitExcept ¶
func NewLimitExcept(value string) *LimitExcept
func (*LimitExcept) BitLen ¶
func (l *LimitExcept) BitLen(_ Order) int
func (*LimitExcept) QueryAllByKeywords ¶
func (l *LimitExcept) QueryAllByKeywords(kw Keywords) (parsers []Parser)
func (*LimitExcept) QueryByKeywords ¶
func (l *LimitExcept) QueryByKeywords(kw Keywords) (parser Parser)
func (*LimitExcept) Size ¶
func (l *LimitExcept) Size(_ Order) int
type Location ¶
type Location struct {
BasicContext `json:"location"`
}
func NewLocation ¶
func (*Location) QueryAllByKeywords ¶
func (*Location) QueryByKeywords ¶
type Map ¶
type Map struct {
BasicContext `json:"map"`
}
func (*Map) QueryAllByKeywords ¶
func (*Map) QueryByKeywords ¶
type Parser ¶
type Parser interface { String() []string Query(parserType, bool, ...string) Parser QueryByKeywords(Keywords) Parser QueryAll(parserType, bool, ...string) []Parser QueryAllByKeywords(Keywords) []Parser BitSize(Order, int) byte BitLen(Order) int Size(Order) int // contains filtered or unexported methods }
func GetHTTPServers ¶
func GetServerName ¶
type Server ¶
type Server struct {
BasicContext `json:"server"`
}
func (*Server) QueryAllByKeywords ¶
func (*Server) QueryByKeywords ¶
type Stream ¶
type Stream struct {
BasicContext `json:"stream"`
}
func (*Stream) QueryAllByKeywords ¶
func (*Stream) QueryByKeywords ¶
type Types ¶
type Types struct {
BasicContext `json:"types"`
}
func (*Types) QueryAllByKeywords ¶
func (*Types) QueryByKeywords ¶
type Upstream ¶
type Upstream struct {
BasicContext `json:"upstream"`
}
func NewUpstream ¶
func (*Upstream) QueryAllByKeywords ¶
func (*Upstream) QueryByKeywords ¶
Click to show internal directories.
Click to hide internal directories.