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

    These constants are the valid values of OpCode.


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


    This section is empty.


    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

              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.