Documentation ¶
Overview ¶
resove 包,该包包含了项目最基础的上下文相关对象,及相关方法及函数 创建者: ClessLi 创建时间:2020-1-17 11:14:15
Index ¶
- Constants
- Variables
- func Backup(config *Config, name string) (path string, err error)
- func Check(config *Config, ng string) (err error)
- func Delete(config *Config) (err error)
- func GetPort(ctx Context) int
- func Save(conf *Config) error
- 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(contents ...Parser)
- func (c *BasicContext) GetIndex(content Parser) int
- func (c *BasicContext) Insert(indexParser Parser, insertParsers ...Parser) error
- func (c *BasicContext) List() (ret []string, err error)
- func (c *BasicContext) Modify(index int, content Parser) error
- func (c *BasicContext) Params() (parsers []Parser)
- func (c *BasicContext) Remove(contents ...Parser)
- func (c *BasicContext) Server() *Server
- func (c *BasicContext) Servers() []Parser
- func (c *BasicContext) String() []string
- type Comment
- type Config
- func (c *Config) BitLen(_ Order) int
- func (c *Config) BitSize(_ Order, _ int) byte
- func (c *Config) List() (ret []string, err error)
- func (c *Config) Query(kw KeyWords) (parser Parser)
- func (c *Config) QueryAll(kw KeyWords) (parsers []Parser)
- func (c *Config) Save() error
- func (c *Config) Size(_ Order) int
- func (c *Config) String() []string
- type Context
- type Events
- type Geo
- type Http
- type If
- type Include
- type Key
- 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 = "config" TypeEvents = "events" TypeGeo = "geo" TypeHttp = "http" TypeIf = "if" TypeInclude = "include" TypeKey = "key" TypeLimitExcept = "limit_except" TypeLocation = "location" TypeMap = "map" TypeServer = "server" TypeStream = "stream" TypeTypes = "types" TypeUpstream = "upstream" TypeComment = "comment" )
Variables ¶
View Source
var ( 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+);`) KeywordHTTP = NewKeyWords(TypeHttp, "", "", false, true) KeywordStream = NewKeyWords(TypeStream, "", "", false, true) KeywordSvrName = NewKeyWords(TypeKey, `server_name`, `*`, false, true) KeywordPort = NewKeyWords(TypeKey, `^listen$`, `.*`, true, true) KeywordLocations = NewKeyWords(TypeLocation, "", `.*`, true, true) )
View Source
var INDENT = " "
Functions ¶
func SortByOrders ¶
func SortInsertInt ¶
func SortInsertUniqInt ¶
func StripSpace ¶
Types ¶
type BasicContext ¶
type BasicContext struct { Name string `json:"-"` Value string `json:"value,omitempty"` Children []Parser `json:"param,omitempty"` }
BasicContext, 上下文基础对象,定义了上下文类型的基本属性及基础方法
func (*BasicContext) Add ¶
func (c *BasicContext) Add(contents ...Parser)
Add, BasicContext 类新增子对象的方法, Context.Add(...Parser) 的实现
func (*BasicContext) GetIndex ¶
func (c *BasicContext) GetIndex(content Parser) int
GetIndex, BasicContext 类子集对象索引值查询的方法, Context.GetIndex(Parser) 的实现
参数:
content: Parser接口对象,各配置对象指针
返回值:
索引值,未查询到时,返回-1
func (*BasicContext) Insert ¶
func (c *BasicContext) Insert(indexParser Parser, insertParsers ...Parser) error
Insert, BasicContext 类插入对象的方法, Context.Insert(indexParser Parser, insertParsers ...Parser) error 的实现
参数:
indexParser: 基准索引子对象 insertParsers: 待插入子对象集
返回值:
错误
func (*BasicContext) List ¶
func (c *BasicContext) List() (ret []string, err error)
func (*BasicContext) Modify ¶
func (c *BasicContext) Modify(index int, content Parser) error
Modify, BasicContext 类修改子对象的方法, Context.Modify(int, Parser) error 的实现
func (*BasicContext) Params ¶
func (c *BasicContext) Params() (parsers []Parser)
func (*BasicContext) Remove ¶
func (c *BasicContext) Remove(contents ...Parser)
Remove, BasicContext 类删除子对象的方法, Context.Remove(...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 ¶
type Config ¶
type Config struct {
BasicContext `json:"config"`
}
type Context ¶
type Context interface { Parser GetIndex(Parser) int Insert(indexParser Parser, insertParsers ...Parser) error Add(...Parser) Remove(...Parser) Modify(int, Parser) error Servers() []Parser Server() *Server Params() []Parser List() ([]string, error) // contains filtered or unexported methods }
Context, 上下文接口对象,定义了上下文接口需实现的增、删、改等方法
type Events ¶
type Events struct {
BasicContext `json:"events"`
}
type Geo ¶
type Geo struct {
BasicContext `json:"geo"`
}
type Http ¶
type Http struct {
BasicContext `json:"http"`
}
type If ¶
type If struct {
BasicContext `json:"if"`
}
type Include ¶
type Include struct { BasicContext `json:"include"` Key *Key `json:"tags"` Comment *Comment `json:"comments"` ConfPWD string `json:"conf_pwd"` }
func NewInclude ¶
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) Query ¶
func (l *LimitExcept) Query(kw KeyWords) (parser Parser)
func (*LimitExcept) QueryAll ¶
func (l *LimitExcept) QueryAll(kw KeyWords) (parsers []Parser)
func (*LimitExcept) Size ¶
func (l *LimitExcept) Size(_ Order) int
type Map ¶
type Map struct {
BasicContext `json:"map"`
}
type Parser ¶
type Parser interface { String() []string Query(KeyWords) Parser QueryAll(KeyWords) []Parser BitSize(Order, int) byte BitLen(Order) int Size(Order) int }
func GetHTTPServers ¶
func GetServerName ¶
type Server ¶
type Server struct {
BasicContext `json:"server"`
}
type Stream ¶
type Stream struct {
BasicContext `json:"stream"`
}
type Types ¶
type Types struct {
BasicContext `json:"types"`
}
Click to show internal directories.
Click to hide internal directories.