nginx

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

resolv.nginx 包,该包包含了bifrost.pkg.resolv.nginx项目最基础的上下文相关对象,及相关方法及函数 创建者: ClessLi 创建时间:2020-1-17 11:14:15

Index

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("unknown 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 Delete

func Delete(config *Config) (err error)

func GetPort

func GetPort(ctx Context) int

func SortByOrders

func SortByOrders(slice *[]Parser, orders ...Order)

func SortInsertInt

func SortInsertInt(slice []int, ints ...int) []int

func SortInsertUniqInt

func SortInsertUniqInt(slice []int, ints ...int) []int

func StripSpace

func StripSpace(s string) string

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 Caches

type Caches map[string]cache

func Load

func Load(path string) (string, Caches, error)

func NewCaches

func NewCaches() Caches

func Save

func Save(conf *Config) (Caches, error)

func SaveWithCheck

func SaveWithCheck(config *Config, ng string) (caches Caches, err error)

func (Caches) CheckHash

func (cs Caches) CheckHash(path string) (bool, error)

func (Caches) GetConfig

func (cs Caches) GetConfig(path string) (*Config, error)

func (Caches) IsCached

func (cs Caches) IsCached(path string) bool

func (*Caches) SetCache

func (cs *Caches) SetCache(config *Config, file ...interface{}) error

type Comment

type Comment struct {
	Comments string `json:"comments"`
	Inline   bool   `json:"inline"`
}

func NewComment

func NewComment(value string, inline bool) *Comment

func (*Comment) BitLen

func (cmt *Comment) BitLen(_ Order) int

func (*Comment) BitSize

func (cmt *Comment) BitSize(_ Order, _ int) byte

func (*Comment) Query

func (cmt *Comment) Query(pType parserType, isRec bool, values ...string) Parser

func (*Comment) QueryAll

func (cmt *Comment) QueryAll(pType parserType, isRec bool, values ...string) []Parser

func (*Comment) QueryAllByKeywords

func (cmt *Comment) QueryAllByKeywords(kw Keywords) (parsers []Parser)

func (*Comment) QueryByKeywords

func (cmt *Comment) QueryByKeywords(kw Keywords) (parser Parser)

func (*Comment) Size

func (cmt *Comment) Size(_ Order) int

func (Comment) String

func (cmt Comment) String() []string

type Config

type Config struct {
	BasicContext `json:"config"`
}

func NewConf

func NewConf(conf []Parser, value string) *Config

func (*Config) BitLen

func (c *Config) BitLen(_ Order) int

func (*Config) BitSize

func (c *Config) BitSize(_ Order, _ int) byte

func (*Config) List

func (c *Config) List() (caches Caches, err error)

func (*Config) QueryAllByKeywords

func (c *Config) QueryAllByKeywords(kw Keywords) (parsers []Parser)

func (*Config) QueryByKeywords

func (c *Config) QueryByKeywords(kw Keywords) (parser Parser)

func (*Config) Save

func (c *Config) Save() (Caches, error)

func (*Config) Size

func (c *Config) Size(_ Order) int

func (Config) String

func (c Config) String() []string

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 NewEvents

func NewEvents() *Events

func (*Events) BitLen

func (e *Events) BitLen(_ Order) int

func (*Events) BitSize

func (e *Events) BitSize(_ Order, _ int) byte

func (*Events) QueryAllByKeywords

func (e *Events) QueryAllByKeywords(kw Keywords) (parsers []Parser)

func (*Events) QueryByKeywords

func (e *Events) QueryByKeywords(kw Keywords) (parser Parser)

func (*Events) Size

func (e *Events) Size(_ Order) int

type Geo

type Geo struct {
	BasicContext `json:"geo"`
}

func NewGeo

func NewGeo(value string) *Geo

func (*Geo) BitLen

func (g *Geo) BitLen(_ Order) int

func (*Geo) BitSize

func (g *Geo) BitSize(_ Order, _ int) byte

func (*Geo) QueryAllByKeywords

func (g *Geo) QueryAllByKeywords(kw Keywords) (parsers []Parser)

func (*Geo) QueryByKeywords

func (g *Geo) QueryByKeywords(kw Keywords) (parser Parser)

func (*Geo) Size

func (g *Geo) Size(_ Order) int

type Http

type Http struct {
	BasicContext `json:"http"`
}

func GetHTTP

func GetHTTP(ctx Context) *Http

func NewHttp

func NewHttp() *Http

func (*Http) BitLen

func (h *Http) BitLen(_ Order) int

func (*Http) BitSize

func (h *Http) BitSize(_ Order, _ int) byte

func (*Http) QueryAllByKeywords

func (h *Http) QueryAllByKeywords(kw Keywords) (parsers []Parser)

func (*Http) QueryByKeywords

func (h *Http) QueryByKeywords(kw Keywords) (parser Parser)

func (*Http) Size

func (h *Http) Size(_ Order) int

type If

type If struct {
	BasicContext `json:"if"`
}

func NewIf

func NewIf(value string) *If

func (*If) BitLen

func (i *If) BitLen(_ Order) int

func (*If) BitSize

func (i *If) BitSize(_ Order, _ int) byte

func (*If) QueryAllByKeywords

func (i *If) QueryAllByKeywords(kw Keywords) (parsers []Parser)

func (*If) QueryByKeywords

func (i *If) QueryByKeywords(kw Keywords) (parser Parser)

func (*If) Size

func (i *If) Size(_ Order) int

type Include

type Include struct {
	BasicContext `json:"include"`
	Key          *Key     `json:"tags"`
	Comment      *Comment `json:"comments"`
	ConfPWD      string   `json:"conf_pwd"`
}

func NewInclude

func NewInclude(dir, paths string, cs *Caches) (*Include, error)

func (*Include) Add

func (i *Include) Add(pType parserType, values ...string) error

func (*Include) AddByParser

func (i *Include) AddByParser(contents ...Parser)

func (*Include) AddConfig

func (i *Include) AddConfig(configs ...Parser) error

func (*Include) BitLen

func (i *Include) BitLen(_ Order) int

func (*Include) BitSize

func (i *Include) BitSize(_ Order, _ int) byte

func (*Include) Insert

func (i *Include) Insert(indexParser Parser, pType parserType, values ...string) error

func (*Include) InsertByParser

func (i *Include) InsertByParser(indexParser Parser, contents ...Parser) error

func (*Include) Modify

func (i *Include) Modify(indexParser Parser, pType parserType, values ...string) error

func (*Include) ModifyByParser

func (i *Include) ModifyByParser(indexParser Parser, content Parser) error

func (*Include) Params

func (i *Include) Params() (parsers []Parser)

func (*Include) Query

func (i *Include) Query(pType parserType, isRec bool, values ...string) Parser

func (*Include) QueryAll

func (i *Include) QueryAll(pType parserType, isRec bool, values ...string) []Parser

func (*Include) QueryAllByKeywords

func (i *Include) QueryAllByKeywords(kw Keywords) (parsers []Parser)

func (*Include) QueryByKeywords

func (i *Include) QueryByKeywords(kw Keywords) Parser

func (*Include) Remove

func (i *Include) Remove(pType parserType, values ...string) error

func (*Include) RemoveByParser

func (i *Include) RemoveByParser(contents ...Parser)

func (*Include) Size

func (i *Include) Size(_ Order) int

func (Include) String

func (i Include) String() []string

type Key

type Key struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

func NewKey

func NewKey(name, value string) *Key

func (*Key) BitLen

func (k *Key) BitLen(_ Order) int

func (*Key) BitSize

func (k *Key) BitSize(_ Order, _ int) byte

func (*Key) Query

func (k *Key) Query(pType parserType, isRec bool, values ...string) Parser

func (*Key) QueryAll

func (k *Key) QueryAll(pType parserType, isRec bool, values ...string) []Parser

func (*Key) QueryAllByKeywords

func (k *Key) QueryAllByKeywords(kw Keywords) (parsers []Parser)

func (*Key) QueryByKeywords

func (k *Key) QueryByKeywords(kw Keywords) (parser Parser)

func (*Key) Size

func (k *Key) Size(_ Order) int

func (Key) String

func (k Key) String() []string

type Keyword

type Keyword struct {
	Type  parserType
	Name  string
	Value string
	IsReg bool
}

type Keywords

type Keywords struct {
	Keyword
	ChildKWs []Keywords
	IsRec    bool
}

func NewKeyWords

func NewKeyWords(contextType parserType, name, value string, isReg, isRec bool, subKWs ...interface{}) Keywords

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) BitSize

func (l *LimitExcept) BitSize(_ Order, _ int) byte

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 NewLocation(value string) *Location

func (*Location) BitLen

func (l *Location) BitLen(_ Order) int

func (*Location) BitSize

func (l *Location) BitSize(_ Order, _ int) byte

func (*Location) QueryAllByKeywords

func (l *Location) QueryAllByKeywords(kw Keywords) (parsers []Parser)

func (*Location) QueryByKeywords

func (l *Location) QueryByKeywords(kw Keywords) (parser Parser)

func (*Location) Size

func (l *Location) Size(_ Order) int

type Map

type Map struct {
	BasicContext `json:"map"`
}

func NewMap

func NewMap(value string) *Map

func (*Map) BitLen

func (m *Map) BitLen(_ Order) int

func (*Map) BitSize

func (m *Map) BitSize(_ Order, _ int) byte

func (*Map) QueryAllByKeywords

func (m *Map) QueryAllByKeywords(kw Keywords) (parsers []Parser)

func (*Map) QueryByKeywords

func (m *Map) QueryByKeywords(kw Keywords) (parser Parser)

func (*Map) Size

func (m *Map) Size(_ Order) int

type Order

type Order int
const (
	ServerName Order = 1000 + iota
)

字符串型order.

const (
	ServerPort Order = iota
)

整型order.

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 GetHTTPServers(ctx Context, orders ...Order) []Parser

func GetPorts

func GetPorts(ctx Context) []Parser

func GetServerName

func GetServerName(ctx Context) Parser

type Server

type Server struct {
	BasicContext `json:"server"`
}

func NewServer

func NewServer() *Server

func (*Server) BitLen

func (s *Server) BitLen(order Order) int

func (*Server) BitSize

func (s *Server) BitSize(order Order, bit int) byte

func (*Server) QueryAllByKeywords

func (s *Server) QueryAllByKeywords(kw Keywords) (parsers []Parser)

func (*Server) QueryByKeywords

func (s *Server) QueryByKeywords(kw Keywords) (parser Parser)

func (*Server) Size

func (s *Server) Size(order Order) int

type Stream

type Stream struct {
	BasicContext `json:"stream"`
}

func GetStream

func GetStream(ctx Context) *Stream

func NewStream

func NewStream() *Stream

func (*Stream) BitLen

func (s *Stream) BitLen(_ Order) int

func (*Stream) BitSize

func (s *Stream) BitSize(_ Order, _ int) byte

func (*Stream) QueryAllByKeywords

func (s *Stream) QueryAllByKeywords(kw Keywords) (parsers []Parser)

func (*Stream) QueryByKeywords

func (s *Stream) QueryByKeywords(kw Keywords) (parser Parser)

func (*Stream) Size

func (s *Stream) Size(_ Order) int

type Types

type Types struct {
	BasicContext `json:"types"`
}

func NewTypes

func NewTypes() *Types

func (*Types) BitLen

func (t *Types) BitLen(_ Order) int

func (*Types) BitSize

func (t *Types) BitSize(_ Order, _ int) byte

func (*Types) QueryAllByKeywords

func (t *Types) QueryAllByKeywords(kw Keywords) (parsers []Parser)

func (*Types) QueryByKeywords

func (t *Types) QueryByKeywords(kw Keywords) (parser Parser)

func (*Types) Size

func (t *Types) Size(_ Order) int

type Upstream

type Upstream struct {
	BasicContext `json:"upstream"`
}

func NewUpstream

func NewUpstream(value string) *Upstream

func (*Upstream) BitLen

func (u *Upstream) BitLen(_ Order) int

func (*Upstream) BitSize

func (u *Upstream) BitSize(_ Order, _ int) byte

func (*Upstream) QueryAllByKeywords

func (u *Upstream) QueryAllByKeywords(kw Keywords) (parsers []Parser)

func (*Upstream) QueryByKeywords

func (u *Upstream) QueryByKeywords(kw Keywords) (parser Parser)

func (*Upstream) Size

func (u *Upstream) Size(_ Order) int

Jump to

Keyboard shortcuts

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