nginx

package
v1.0.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

resove 包,该包包含了项目最基础的上下文相关对象,及相关方法及函数 创建者: 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      = "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 Backup

func Backup(config *Config, name string) (path string, err error)

func Check

func Check(config *Config, ng string) (err error)

func Delete

func Delete(config *Config) (err error)

func GetPort

func GetPort(ctx Context) int

func Save

func Save(conf *Config) error

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

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(kw KeyWords) (parser Parser)

func (*Comment) QueryAll

func (cmt *Comment) QueryAll(kw KeyWords) (parsers []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 Load

func Load(path string) (*Config, error)

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() (ret []string, err error)

func (*Config) Query

func (c *Config) Query(kw KeyWords) (parser Parser)

func (*Config) QueryAll

func (c *Config) QueryAll(kw KeyWords) (parsers []Parser)

func (*Config) Save

func (c *Config) Save() error

func (*Config) Size

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

func (*Config) String

func (c *Config) String() []string

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"`
}

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

func (e *Events) Query(kw KeyWords) (parser Parser)

func (*Events) QueryAll

func (e *Events) QueryAll(kw KeyWords) (parsers []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) Query

func (g *Geo) Query(kw KeyWords) (parser Parser)

func (*Geo) QueryAll

func (g *Geo) QueryAll(kw KeyWords) (parsers []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) Query

func (h *Http) Query(kw KeyWords) (parser Parser)

func (*Http) QueryAll

func (h *Http) QueryAll(kw KeyWords) (parsers []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) Query

func (i *If) Query(kw KeyWords) (parser Parser)

func (*If) QueryAll

func (i *If) QueryAll(kw KeyWords) (parsers []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, allConfigs *map[string]*Config, configCaches *[]string) (*Include, error)

func (*Include) BitLen

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

func (*Include) BitSize

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

func (*Include) Query

func (i *Include) Query(kw KeyWords) (parser Parser)

func (*Include) QueryAll

func (i *Include) QueryAll(kw KeyWords) (parsers []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(kw KeyWords) (parser Parser)

func (*Key) QueryAll

func (k *Key) QueryAll(kw KeyWords) (parsers []Parser)

func (*Key) Size

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

func (*Key) String

func (k *Key) String() []string

type KeyWord

type KeyWord struct {
	Type  string
	Name  string
	Value string
	IsReg bool
}

type KeyWords

type KeyWords struct {
	KeyWord
	ChildKWs []KeyWords
	IsRec    bool
}

func NewKeyWords

func NewKeyWords(contextType, 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) 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 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) Query

func (l *Location) Query(kw KeyWords) (parser Parser)

func (*Location) QueryAll

func (l *Location) QueryAll(kw KeyWords) (parsers []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) Query

func (m *Map) Query(kw KeyWords) (parser Parser)

func (*Map) QueryAll

func (m *Map) QueryAll(kw KeyWords) (parsers []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(KeyWords) Parser
	QueryAll(KeyWords) []Parser
	BitSize(Order, int) byte
	BitLen(Order) int
	Size(Order) int
}

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

func (s *Server) Query(kw KeyWords) (parser Parser)

func (*Server) QueryAll

func (s *Server) QueryAll(kw KeyWords) (parsers []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) Query

func (s *Stream) Query(kw KeyWords) (parser Parser)

func (*Stream) QueryAll

func (s *Stream) QueryAll(kw KeyWords) (parsers []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) Query

func (t *Types) Query(kw KeyWords) (parser Parser)

func (*Types) QueryAll

func (t *Types) QueryAll(kw KeyWords) (parsers []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) Query

func (u *Upstream) Query(kw KeyWords) (parser Parser)

func (*Upstream) QueryAll

func (u *Upstream) QueryAll(kw KeyWords) (parsers []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