httppattern

package
v0.0.0-...-da93f2a Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//  The special segment keys during uri template parsing.
	SingleParameterKey = "/."
	SingleWildCardKey  = "*"
	DoubleWildCardKey  = "**"

	HttpMethodWildCard = "*"
)
View Source
const (
	InvalidChar = byte(0)
)

Use null char to denote coming into invalid char.

Variables

This section is empty.

Functions

func DoubleWildcardReplacementRegex

func DoubleWildcardReplacementRegex(disallowColonInWildcardPathSegment bool) string

DoubleWildcardReplacementRegex does wildcard segment matching any char 0 or unlimited times, except '/'. If disallowColonInWildcardPathSegment=true, it matches any char except '/' and ':'.

func SingleWildcardReplacementRegex

func SingleWildcardReplacementRegex(disallowColonInWildcardPathSegment bool) string

SingleWildcardReplacementRegex does wildcard segment matching any char 1 or unlimited times, except '/'. If disallowColonInWildcardPathSegment=true, it matches any char except '/' and ':'.

func Sort

func Sort(methods *MethodSlice) error

Sort the slice of methods, based on the http patterns. It will raise errors:

  • methods with duplicate http pattern
  • invalid uri template

The time complexity is O(W * L), where W is the size of slice and L is the size of uri template segments

Types

type Method

type Method struct {
	*Pattern
	Operation string
}

type MethodSlice

type MethodSlice []*Method

func (*MethodSlice) AppendMethod

func (sr *MethodSlice) AppendMethod(m *Method)

type Pattern

type Pattern struct {
	HttpMethod string
	*UriTemplate
}

Pattern Corresponds espv2.api.envoy.v12.http.common.Pattern and it holds the syntax parsing result for uri template.

type UriTemplate

type UriTemplate struct {
	Segments  []string
	Verb      string
	Variables []*variable
	// The original uri template string before parsing.
	// It is ignored when calling `String` or `Equal`
	Origin string
}

UriTemplate keeps information of the uri template string. It follows the grammar: https://github.com/googleapis/googleapis/blob/e5211c547d63632963f9125e2b333185d57ff8f6/google/api/http.proto#L224.

func ParseUriTemplate

func ParseUriTemplate(input string) (*UriTemplate, error)

func (*UriTemplate) Equal

func (u *UriTemplate) Equal(v *UriTemplate) bool

Check if two uriTemplates are equal. Ignore `Origin`

func (*UriTemplate) ExactMatchString

func (u *UriTemplate) ExactMatchString(acceptTrailingBackslash bool) string

func (*UriTemplate) IsExactMatch

func (u *UriTemplate) IsExactMatch() bool

func (*UriTemplate) IsGRPCPathForOperation

func (u *UriTemplate) IsGRPCPathForOperation(selector string) (bool, error)

func (*UriTemplate) Regex

func (u *UriTemplate) Regex(disallowColonInWildcardPathSegment bool) string

Generate regular expression of the current uri template.

func (*UriTemplate) ReplaceVariableField

func (u *UriTemplate) ReplaceVariableField(fieldMapping map[string]string)

Replace all the variable fields found in the input map.

func (*UriTemplate) String

func (u *UriTemplate) String() string

Output the string representation with defaults.

Jump to

Keyboard shortcuts

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