rewrite

package
v0.2.52 Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Rewrite1 added in v0.2.32

func Rewrite1() gin.HandlerFunc

Rewrite returns a Rewrite middleware. Rewrite middleware rewrites the URL path based on the provided rules.

Types

type ComplexRule added in v0.2.32

type ComplexRule struct {
	// Path base. Request to this path and subpaths will be rewritten
	Base string

	// Path to rewrite to
	To string

	// Extensions to filter by
	Exts []string

	// Request matcher
	httpserver.RequestMatcher

	Regexp *regexp.Regexp
}

ComplexRule is a rewrite rule based on a regular expression

func NewComplexRule added in v0.2.32

func NewComplexRule(base, pattern, to string, ext []string, matcher httpserver.RequestMatcher) (ComplexRule, error)

NewComplexRule creates a new RegexpRule. It returns an error if regexp pattern (pattern) or extensions (ext) are invalid.

func (ComplexRule) BasePath added in v0.2.32

func (r ComplexRule) BasePath() string

BasePath satisfies httpserver.Config

func (ComplexRule) Match added in v0.2.32

func (r ComplexRule) Match(req *http.Request) bool

Match satisfies httpserver.Config.

Though ComplexRule embeds a RequestMatcher, additional checks are needed which requires a custom implementation.

func (ComplexRule) Rewrite added in v0.2.32

func (r ComplexRule) Rewrite(fs http.FileSystem, req *http.Request) (re Result)

Rewrite rewrites the internal location of the current request.

type Result added in v0.2.32

type Result int

Result is the result of a rewrite

const (
	// RewriteIgnored is returned when rewrite is not done on request.
	RewriteIgnored Result = iota
	// RewriteDone is returned when rewrite is done on request.
	RewriteDone
)

func To added in v0.2.32

func To(fs http.FileSystem, r *http.Request, to string, replacer httpserver.Replacer) Result

To attempts rewrite. It attempts to rewrite to first valid path or the last path if none of the paths are valid.

type Rewrite

type Rewrite struct {
	Next    httpserver.Handler
	FileSys http.FileSystem
	Rules   []httpserver.HandlerConfig
}

Rewrite is middleware to rewrite request locations internally before being handled.

func (Rewrite) ServeHTTP added in v0.2.32

func (rw Rewrite) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)

ServeHTTP implements the httpserver.Handler interface.

type Rule added in v0.2.32

type Rule interface {
	httpserver.HandlerConfig
	// Rewrite rewrites the internal location of the current request.
	Rewrite(http.FileSystem, *http.Request) Result
}

Rule describes an internal location rewrite rule.

type SimpleRule added in v0.2.32

type SimpleRule struct {
	Regexp *regexp.Regexp
	To     string
	Negate bool
}

SimpleRule is a simple rewrite rule.

func NewSimpleRule added in v0.2.32

func NewSimpleRule(from, to string, negate bool) (*SimpleRule, error)

NewSimpleRule creates a new Simple Rule

func (SimpleRule) BasePath added in v0.2.32

func (s SimpleRule) BasePath() string

BasePath satisfies httpserver.Config

func (*SimpleRule) Match added in v0.2.32

func (s *SimpleRule) Match(r *http.Request) bool

Match satisfies httpserver.Config

func (*SimpleRule) Rewrite added in v0.2.32

func (s *SimpleRule) Rewrite(fs http.FileSystem, r *http.Request) Result

Rewrite rewrites the internal location of the current request.

Jump to

Keyboard shortcuts

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