rewrite

package
v12.2.11 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: BSD-3-Clause Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(filename string) router.WrapperFunc

Load decodes the "filename" options and returns a new Rewrite Engine Router Wrapper. It panics on errors. Usage: redirects := Load("redirects.yml") app.WrapRouter(redirects) See `New` too.

Types

type Engine

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

Rewrite is a struct that represents a rewrite engine for Iris web framework. It contains a slice of redirect rules, an options struct, a logger, and a domain validator function. It provides methods to create, configure, and apply rewrite rules to HTTP requests and responses.

Navigate through _examples/routing/rewrite for more.

func New

func New(opts Options) (*Engine, error)

New returns a new Rewrite Engine based on "opts". It reports any parser error. See its `Handler` or `Rewrite` methods. Depending on the needs, select one.

func (*Engine) Handler

func (e *Engine) Handler(ctx *context.Context)

Handler is an Iris Handler that can be used as a router or party or route middleware. For a global alternative, if you want to wrap the entire Iris Application use the `Wrapper` instead. Usage: app.UseRouter(engine.Handler)

func (*Engine) Rewrite

func (e *Engine) Rewrite(w http.ResponseWriter, r *http.Request, routeHandler http.HandlerFunc)

Rewrite is used to wrap the entire Iris Router. Rewrite is a bit faster than Handler because it's executed even before any route matched and it stops on redirect pattern match. Use it to wrap the entire Iris Application, otherwise look `Handler` instead.

Usage: app.WrapRouter(engine.Rewrite).

func (*Engine) SetLogger

func (e *Engine) SetLogger(logger *golog.Logger) *Engine

SetLogger attachs a logger to the Rewrite Engine, used only for debugging. Defaults to nil.

type Options

type Options struct {
	// RedirectMatch accepts a slice of lines
	// of form:
	// REDIRECT_CODE PATH_PATTERN TARGET_PATH
	// Example: []{"301 /seo/(.*) /$1"}.
	RedirectMatch []string `json:"redirectMatch" yaml:"RedirectMatch"`

	// Root domain requests redirect automatically to primary subdomain.
	// Example: "www" to redirect always to www.
	// Note that you SHOULD NOT create a www subdomain inside the Iris Application.
	// This field takes care of it for you, the root application instance
	// will be used to serve the requests.
	PrimarySubdomain string `json:"primarySubdomain" yaml:"PrimarySubdomain"`
}

Options holds the developer input to customize the redirects for the Rewrite Engine. Look the `New` and `Load` package-level functions.

func LoadOptions

func LoadOptions(filename string) (opts Options)

LoadOptions loads rewrite Options from a system file.

Jump to

Keyboard shortcuts

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