router

package
v3.3.3 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2022 License: Apache-2.0, BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// OpNop does nothing
	OpNop = OpCode(iota)
	// OpPush pushes a component to stack
	OpPush
	// OpLitPush pushes a component to stack if it matches to the literal
	OpLitPush
	// OpPushM concatenates the remaining components and pushes it to stack
	OpPushM
	// OpConcatN pops N items from stack, concatenates them and pushes it back to stack
	OpConcatN
	// OpCapture pops an item and binds it to the variable
	OpCapture
	// OpEnd is the least positive invalid opcode.
	OpEnd
)

These constants are the valid values of OpCode.

Variables

View Source
var (
	// ErrNotMatch indicates that the given HTTP request path does not match to the pattern.
	ErrNotMatch = errors.New("not match to the path pattern")
	// ErrInvalidPattern indicates that the given definition of Pattern is not valid.
	ErrInvalidPattern = errors.New("invalid pattern")
)

Functions

func New

func New(srvs []*registry.Service) router.Router

Router is a hack for API routing

Types

type Compiler

type Compiler interface {
	Compile() Template
}

Compiler compiles utilities representation of path templates into marshallable operations. They can be unmarshalled by runtime.NewPattern.

func Parse

func Parse(tmpl string) (Compiler, error)

Parse parses the string representation of path template

type InvalidTemplateError

type InvalidTemplateError struct {
	// contains filtered or unexported fields
}

InvalidTemplateError indicates that the path template is not valid.

func (InvalidTemplateError) Error

func (e InvalidTemplateError) Error() string

type OpCode

type OpCode int

An OpCode is a opcode of compiled path patterns.

type Pattern

type Pattern struct {
	// contains filtered or unexported fields
}

Pattern is a template pattern of http request paths defined in github.com/googleapis/googleapis/google/api/http.proto.

func MustPattern

func MustPattern(p Pattern, err error) Pattern

MustPattern is a helper function which makes it easier to call NewPattern in variable initialization.

func NewPattern

func NewPattern(version int, ops []int, pool []string, verb string, opts ...PatternOpt) (Pattern, error)

NewPattern returns a new Pattern from the given definition values. "ops" is a sequence of op codes. "pool" is a constant pool. "verb" is the verb part of the pattern. It is empty if the pattern does not have the part. "version" must be 1 for now. It returns an error if the given definition is invalid.

func (Pattern) Match

func (p Pattern) Match(components []string, verb string) (map[string]string, error)

Match examines components if it matches to the Pattern. If it matches, the function returns a mapping from field paths to their captured values. If otherwise, the function returns an error.

func (Pattern) String

func (p Pattern) String() string

func (Pattern) Verb

func (p Pattern) Verb() string

Verb returns the verb part of the Pattern.

type PatternOpt

type PatternOpt func(*patternOptions)

PatternOpt is an option for creating Patterns.

func AssumeColonVerbOpt

func AssumeColonVerbOpt(val bool) PatternOpt

AssumeColonVerbOpt indicates whether a path suffix after a final colon may only be interpreted as a verb.

type Template

type Template struct {
	// Version is the version number of the format.
	Version int
	// OpCodes is a sequence of operations.
	OpCodes []int
	// Pool is a constant pool
	Pool []string
	// Verb is a VERB part in the template.
	Verb string
	// Fields is a list of field paths bound in this template.
	Fields []string
	// Original template (example: /v1/a_bit_of_everything)
	Template string
}

Template is a compiled representation of path templates.

Jump to

Keyboard shortcuts

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