directive

package
v0.0.0-...-e1804a1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSyntax = errors.New("syntax error")

Functions

func RegisterFactory

func RegisterFactory(n ProcessorFactory)

RegisterFactory registers a processor factory for a directive.

Types

type Location

type Location struct {
	Seq        int              // 定义的顺序
	Priority   ModifierPriority // 匹配级别,从0开始,数字越小,匹配优先级越高
	Modifier   Modifier
	Path       string
	Processors Processors
	Pattern    *regexp.Regexp
}

Location is the location.

func (Location) Matches

func (l Location) Matches(p ModifierPriority, r *http.Request) bool

func (*Location) Parse

func (l *Location) Parse(directive string, params []string) bool

func (Location) ServeHTTP

func (l Location) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Locations

type Locations []Location

func (Locations) FindLocation

func (ls Locations) FindLocation(r *http.Request) *Location

func (Locations) Len

func (ls Locations) Len() int

func (Locations) Less

func (ls Locations) Less(i, j int) bool

func (Locations) Swap

func (ls Locations) Swap(i, j int)

type Modifier

type Modifier string

Modifier is the location modifier.

func (Modifier) Priority

func (m Modifier) Priority() ModifierPriority

Priority returns the priority of the location matching.

type ModifierPriority

type ModifierPriority int

ModifierPriority defines the priority of the modifier. https://end0tknr.wordpress.com/2015/12/22/location-match-priority-in-nginx/. https://artfulrobot.uk/blog/untangling-nginx-location-block-matching-algorithm. https://blog.csdn.net/qq_15766181/article/details/72829672. priority | prefix | example. 1 | = (exactly) | location = /path. 2 | ^~ (forward match) | location = /image. 3 | ~ or ~* (regular & case-(in)sensitive) | location ~ /image/. 4 | NONE (forward match) | location /image.

const (
	// ModifierExactly like location = /path matches the query / only.
	ModifierExactly ModifierPriority = iota + 1
	// ModifierForward like location ^~ /path.
	// matches any query beginning with /path/ and halts searching,
	// so regular expressions will not be checked.
	ModifierForward
	// ModifierRegular like location ~ \.(gif|jpg|jpeg)$
	// or like location ~* .(jpg|png|bmp).
	ModifierRegular
	// ModifierNone means none modifier for the location.
	ModifierNone
)

https://stackoverflow.com/questions/5238377/nginx-location-priority

type Naming

type Naming interface {
	Name() map[string]bool
}

type ProcessResult

type ProcessResult int
const (
	ProcessContinue ProcessResult = iota
	ProcessTerminate
)

func Welcome

type ProcessSeq

type ProcessSeq int
const (
	Continue ProcessSeq = iota
	Terminate
)

type Processor

type Processor interface {
	Naming
	GetProcessSeq() ProcessSeq
	Parse(path string, name string, params []string) error
	Do(l Location, w http.ResponseWriter, r *http.Request) ProcessResult
}

Processor is the directive processor in a location.

type ProcessorFactory

type ProcessorFactory interface {
	Naming
	Create() Processor
}

type Processors

type Processors []Processor

Processors is the slice of processors for sorting Interface satisfied.

func (Processors) Len

func (l Processors) Len() int

func (Processors) Less

func (l Processors) Less(i, j int) bool

func (Processors) Swap

func (l Processors) Swap(i, j int)

type Return

type Return struct {
	Code int
	Text string
	// contains filtered or unexported fields
}

Return means http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#return. Syntax: return code [text];.

func (Return) Create

func (i Return) Create() Processor

func (*Return) Do

func (*Return) GetProcessSeq

func (r *Return) GetProcessSeq() ProcessSeq

func (Return) Name

func (Return) Name() map[string]bool

func (*Return) Parse

func (r *Return) Parse(path string, name string, params []string) error

Jump to

Keyboard shortcuts

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