local

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: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DoubleQuotes = `\s*"[^"]*"`
	SingleQuotes = `\s*'[^']*'`
	Normal       = `\s*[^;\s#]+`
	Abnormal     = `^[\n\r\t\f ]*;.*`
	LineBreak    = `[\n\r]`
	S1           = DoubleQuotes + `|` + SingleQuotes + `|` + Normal
	S            = `^\s*(` + S1 + `)\s+((?:` + S1 + `)+)\s*;`
)
View Source
const INDENT = "    "

Variables

View Source
var (

	// regexps
	RegCommentHead           = regexp.MustCompile(`^(\s*)#+[ \t\f]*([^\r\n]*?)` + LineBreak + `+`)
	RegDirectiveWithValue    = regexp.MustCompile(S)
	RegDirectiveWithoutValue = regexp.MustCompile(`^\s*(` + Normal + `)\s*;`)
	RegEventsHead            = regexp.MustCompile(`^\s*events\s*{`)
	RegGeoHead               = regexp.MustCompile(`^\s*geo\s*([^;]*?)\s*{`)
	RegHttpHead              = regexp.MustCompile(`^\s*http\s*{`)
	RegIfHead                = regexp.MustCompile(`^\s*if\s*([^;]*?)\s*{`)
	RegLimitExceptHead       = regexp.MustCompile(`^\s*limit_except\s*([^;]*?)\s*{`)
	RegLocationHead          = regexp.MustCompile(`^\s*location\s*([^;]*?)\s*{`)
	RegMapHead               = regexp.MustCompile(`^\s*map\s*([^;]*?)\s*{`)
	RegServerHead            = regexp.MustCompile(`^\s*server\s*{`)
	RegStreamHead            = regexp.MustCompile(`^\s*stream\s*{`)
	RegTypesHead             = regexp.MustCompile(`^\s*types\s*{`)
	RegUpstreamHead          = regexp.MustCompile(`^\s*upstream\s*([^;]*?)\s*{`)
	RegBlankLine             = regexp.MustCompile(`^` + LineBreak + `\s*` + LineBreak + `$`)
	RegBraceEnd              = regexp.MustCompile(`^\s*}`)
	RegErrorHeed             = regexp.MustCompile(Abnormal)
	RegLineBreak             = regexp.MustCompile(LineBreak)

	// json unmarshal regexps
	JsonUnmarshalRegCommentHead     = regexp.MustCompile(`^\s*{[^{]*"comments"\s*:\s*"`)
	JsonUnmarshalRegEventsHead      = regexp.MustCompile(`^\s*{\s*"events"\s*:\s*{`)
	JsonUnmarshalRegGeoHead         = regexp.MustCompile(`^\s*{\s*"geo"\s*:\s*{`)
	JsonUnmarshalRegHttpHead        = regexp.MustCompile(`^\s*{\s*"http"\s*:\s*{`)
	JsonUnmarshalRegIfHead          = regexp.MustCompile(`^\s*{\s*"if"\s*:\s*{`)
	JsonUnmarshalRegIncludeHead     = regexp.MustCompile(`^\s*{\s*"include"\s*:\s*{`)
	JsonUnmarshalRegLimitExceptHead = regexp.MustCompile(`^\s*{\s*"limit_except"\s*:\s*{`)
	JsonUnmarshalRegLocationHead    = regexp.MustCompile(`^\s*{\s*"location"\s*:\s*{`)
	JsonUnmarshalRegMapHead         = regexp.MustCompile(`^\s*{\s*"map"\s*:\s*{`)
	JsonUnmarshalRegServerHead      = regexp.MustCompile(`^\s*{\s*"server"\s*:\s*{`)
	JsonUnmarshalRegStreamHead      = regexp.MustCompile(`^\s*{\s*"stream"\s*:\s*{`)
	JsonUnmarshalRegTypesHead       = regexp.MustCompile(`^\s*{\s*"types"\s*:\s*{`)
	JsonUnmarshalRegUpstreamHead    = regexp.MustCompile(`^\s*{\s*"upstream"\s*:\s*{`)
)

Functions

func NewContext

func NewContext(contextType context_type.ContextType, value string) context.Context

func RegisterBuilder

func RegisterBuilder(opts context.BuildOptions, registrar ContextBuilderRegistrar) error

func RegisterParseFunc

func RegisterParseFunc(opts parseFuncBuildOptions, parserFunc map[context_type.ContextType]parseFunc) error

Types

type BasicContext

type BasicContext struct {
	ContextType  context_type.ContextType `json:"context-type"`
	ContextValue string                   `json:"value,omitempty"`
	Children     []context.Context        `json:"params,omitempty"`
	// contains filtered or unexported fields
}

func (*BasicContext) Child

func (b *BasicContext) Child(idx int) context.Context

func (*BasicContext) Clone

func (b *BasicContext) Clone() context.Context

func (*BasicContext) ConfigLines

func (b *BasicContext) ConfigLines(isDumping bool) ([]string, error)

func (*BasicContext) Error

func (b *BasicContext) Error() error

func (*BasicContext) Father

func (b *BasicContext) Father() context.Context

func (*BasicContext) HasChild

func (b *BasicContext) HasChild() bool

func (*BasicContext) Insert

func (b *BasicContext) Insert(ctx context.Context, idx int) context.Context

func (*BasicContext) Len

func (b *BasicContext) Len() int

func (*BasicContext) Modify

func (b *BasicContext) Modify(ctx context.Context, idx int) context.Context

func (*BasicContext) QueryAllByKeyWords

func (b *BasicContext) QueryAllByKeyWords(kw context.KeyWords) []context.Pos

func (*BasicContext) QueryByKeyWords

func (b *BasicContext) QueryByKeyWords(kw context.KeyWords) context.Pos

func (*BasicContext) Remove

func (b *BasicContext) Remove(idx int) context.Context

func (*BasicContext) SetFather

func (b *BasicContext) SetFather(ctx context.Context) error

func (*BasicContext) SetValue

func (b *BasicContext) SetValue(v string) error

func (*BasicContext) Type

func (*BasicContext) Value

func (b *BasicContext) Value() string

type BuildBasicContextConfig

type BuildBasicContextConfig struct {
	ContextType context_type.ContextType
	// contains filtered or unexported fields
}

func (BuildBasicContextConfig) BasicContext

func (b BuildBasicContextConfig) BasicContext() *BasicContext

type Comment

type Comment struct {
	Comments string
	Inline   bool
	// contains filtered or unexported fields
}

func (*Comment) Child

func (c *Comment) Child(idx int) context.Context

func (*Comment) Clone

func (c *Comment) Clone() context.Context

func (*Comment) ConfigLines

func (c *Comment) ConfigLines(isDumping bool) ([]string, error)

func (*Comment) Error

func (c *Comment) Error() error

func (*Comment) Father

func (c *Comment) Father() context.Context

func (*Comment) HasChild

func (c *Comment) HasChild() bool

func (*Comment) Insert

func (c *Comment) Insert(ctx context.Context, idx int) context.Context

func (*Comment) Len

func (c *Comment) Len() int

func (*Comment) MarshalJSON added in v1.0.12

func (c *Comment) MarshalJSON() ([]byte, error)

func (*Comment) Modify

func (c *Comment) Modify(ctx context.Context, idx int) context.Context

func (*Comment) QueryAllByKeyWords

func (c *Comment) QueryAllByKeyWords(kw context.KeyWords) []context.Pos

func (*Comment) QueryByKeyWords

func (c *Comment) QueryByKeyWords(kw context.KeyWords) context.Pos

func (*Comment) Remove

func (c *Comment) Remove(idx int) context.Context

func (*Comment) SetFather

func (c *Comment) SetFather(ctx context.Context) error

func (*Comment) SetValue

func (c *Comment) SetValue(v string) error

func (*Comment) Type

func (c *Comment) Type() context_type.ContextType

func (*Comment) Value

func (c *Comment) Value() string

type Config

type Config struct {
	BasicContext
	context.ConfigPath `json:"-"`
}

func (*Config) Clone

func (c *Config) Clone() context.Context

func (*Config) ConfigLines

func (c *Config) ConfigLines(isDumping bool) ([]string, error)

func (*Config) SetFather

func (c *Config) SetFather(ctx context.Context) error

func (*Config) SetValue

func (c *Config) SetValue(v string) error

type ConfigGraph

type ConfigGraph interface {
	AddEdge(src, dst *Config) error
	RemoveEdge(src, dst *Config) error
	Topology() []*Config
	MainConfig() *Config
	AddConfig(config *Config) error
	GetConfig(fullpath string) (*Config, error)
	RenewConfigPath(fullpath string) error
}

type ContextBuilderRegistrar

type ContextBuilderRegistrar func(func() *BasicContext) func(value string) context.Context

type Directive

type Directive struct {
	Name   string
	Params string
	// contains filtered or unexported fields
}

func (*Directive) Child

func (d *Directive) Child(idx int) context.Context

func (*Directive) Clone

func (d *Directive) Clone() context.Context

func (*Directive) ConfigLines

func (d *Directive) ConfigLines(isDumping bool) ([]string, error)

func (*Directive) Error

func (d *Directive) Error() error

func (*Directive) Father

func (d *Directive) Father() context.Context

func (*Directive) HasChild

func (d *Directive) HasChild() bool

func (*Directive) Insert

func (d *Directive) Insert(ctx context.Context, idx int) context.Context

func (*Directive) Len

func (d *Directive) Len() int

func (*Directive) MarshalJSON added in v1.0.12

func (d *Directive) MarshalJSON() ([]byte, error)

func (*Directive) Modify

func (d *Directive) Modify(ctx context.Context, idx int) context.Context

func (*Directive) QueryAllByKeyWords

func (d *Directive) QueryAllByKeyWords(kw context.KeyWords) []context.Pos

func (*Directive) QueryByKeyWords

func (d *Directive) QueryByKeyWords(kw context.KeyWords) context.Pos

func (*Directive) Remove

func (d *Directive) Remove(idx int) context.Context

func (*Directive) SetFather

func (d *Directive) SetFather(ctx context.Context) error

func (*Directive) SetValue

func (d *Directive) SetValue(v string) error

func (*Directive) Type

func (*Directive) Value

func (d *Directive) Value() string

type Include

type Include struct {
	ContextValue string
	Configs      map[string]*Config
	// contains filtered or unexported fields
}

func (*Include) Child

func (i *Include) Child(idx int) context.Context

func (*Include) ChildConfig

func (i *Include) ChildConfig(fullpath string) (*Config, error)

func (*Include) Clone

func (i *Include) Clone() context.Context

func (*Include) ConfigLines

func (i *Include) ConfigLines(isDumping bool) ([]string, error)

func (*Include) Error

func (i *Include) Error() error

func (*Include) Father

func (i *Include) Father() context.Context

func (*Include) FatherConfig

func (i *Include) FatherConfig() (*Config, error)

func (*Include) HasChild

func (i *Include) HasChild() bool

func (*Include) Insert

func (i *Include) Insert(ctx context.Context, idx int) context.Context

func (*Include) InsertConfig

func (i *Include) InsertConfig(configs ...*Config) error

func (*Include) Len

func (i *Include) Len() int

func (*Include) MarshalJSON

func (i *Include) MarshalJSON() ([]byte, error)

func (*Include) Modify

func (i *Include) Modify(ctx context.Context, idx int) context.Context

func (*Include) ModifyConfig

func (i *Include) ModifyConfig(configs ...*Config) error

func (*Include) QueryAllByKeyWords

func (i *Include) QueryAllByKeyWords(kw context.KeyWords) []context.Pos

func (*Include) QueryByKeyWords

func (i *Include) QueryByKeyWords(kw context.KeyWords) context.Pos

func (*Include) Remove

func (i *Include) Remove(idx int) context.Context

func (*Include) RemoveConfig

func (i *Include) RemoveConfig(configs ...*Config) error

func (*Include) SetFather

func (i *Include) SetFather(ctx context.Context) error

func (*Include) SetValue

func (i *Include) SetValue(v string) error

func (*Include) Type

func (i *Include) Type() context_type.ContextType

func (*Include) Value

func (i *Include) Value() string

type Loader

type Loader interface {
	Load() (MainContext, error)
}

func FileLoader

func FileLoader(configpath string) Loader

func JsonLoader

func JsonLoader(data []byte) Loader

type Main

type Main struct {
	ConfigGraph
}

func (*Main) Child

func (m *Main) Child(idx int) context.Context

func (*Main) Clone

func (m *Main) Clone() context.Context

func (*Main) ConfigLines

func (m *Main) ConfigLines(isDumping bool) ([]string, error)

func (*Main) Error

func (m *Main) Error() error

func (*Main) Father

func (m *Main) Father() context.Context

func (*Main) HasChild

func (m *Main) HasChild() bool

func (*Main) Insert

func (m *Main) Insert(ctx context.Context, idx int) context.Context

func (*Main) Len

func (m *Main) Len() int

func (*Main) MarshalJSON

func (m *Main) MarshalJSON() ([]byte, error)

func (*Main) Modify

func (m *Main) Modify(ctx context.Context, idx int) context.Context

func (*Main) QueryAllByKeyWords

func (m *Main) QueryAllByKeyWords(kw context.KeyWords) []context.Pos

func (*Main) QueryByKeyWords

func (m *Main) QueryByKeyWords(kw context.KeyWords) context.Pos

func (*Main) Remove

func (m *Main) Remove(idx int) context.Context

func (*Main) SetFather

func (m *Main) SetFather(ctx context.Context) error

func (*Main) SetValue

func (m *Main) SetValue(v string) error

func (*Main) Type

func (m *Main) Type() context_type.ContextType

func (*Main) Value

func (m *Main) Value() string

type MainContext

type MainContext interface {
	context.Context
	ConfigGraph
	// contains filtered or unexported methods
}

func NewMain

func NewMain(abspath string) (MainContext, error)

Jump to

Keyboard shortcuts

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