redirector

package module
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2021 License: MIT Imports: 6 Imported by: 0

README

Redirector

PkgGoDev

A useful gas that used to redirect unintended requests for the web applications built using Air.

Installation

Open your terminal and execute

$ go get github.com/air-gases/redirector

done.

The only requirement is the Go, at least v1.13.

Usage

The following application will redirect all www requests to non-www:

package main

import (
	"github.com/air-gases/redirector"
	"github.com/aofei/air"
)

func main() {
	a := air.Default
	a.DebugMode = true
	a.Pregases = []air.Gas{
		redirector.WWW2NonWWWGas(redirector.WWW2NonWWWGasConfig{}),
	}
	a.GET("/", func(req *air.Request, res *air.Response) error {
		return res.WriteString("Absolutely non-www.")
	})
	a.Serve()
}

The following application will redirect all non-www requests to www:

package main

import (
	"github.com/air-gases/redirector"
	"github.com/aofei/air"
)

func main() {
	a := air.Default
	a.DebugMode = true
	a.Gases = []air.Gas{
		redirector.NonWWW2WWWGas(redirector.NonWWW2WWWGasConfig{}),
	}
	a.GET("/", func(req *air.Request, res *air.Response) error {
		return res.WriteString("Absolutely www.")
	})
	a.Serve()
}

Community

If you want to discuss Redirector, or ask questions about it, simply post questions or ideas here.

Contributing

If you want to help build Redirector, simply follow this to send pull requests here.

License

This project is licensed under the MIT License.

License can be found here.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NonWWW2WWWGas

func NonWWW2WWWGas(nw2wgc NonWWW2WWWGasConfig) air.Gas

NonWWW2WWWGas returns an `air.Gas` that is used to redirect non-www requests to www.

func OneHostGas

func OneHostGas(oagc OneHostGasConfig) air.Gas

OneHostGas returns an `air.Gas` that is used to ensure that there is only one host.

func WWW2NonWWWGas

func WWW2NonWWWGas(w2nwgc WWW2NonWWWGasConfig) air.Gas

WWW2NonWWWGas returns an `air.Gas` that is used to redirect www requests to non-www.

Types

type NonWWW2WWWGasConfig

type NonWWW2WWWGasConfig struct {
	HTTPSEnforced bool

	Skippable func(*air.Request, *air.Response) bool
}

NonWWW2WWWGasConfig is a set of configurations for the `NonWWW2WWWGas`.

type OneHostGasConfig

type OneHostGasConfig struct {
	Host          string
	HTTPSEnforced bool

	Skippable func(*air.Request, *air.Response) bool
}

OneHostGasConfig is a set of configurations for the `OneHostGas`.

type WWW2NonWWWGasConfig

type WWW2NonWWWGasConfig struct {
	HTTPSEnforced bool

	Skippable func(*air.Request, *air.Response) bool
}

WWW2NonWWWGasConfig is a set of configurations for the `WWW2NonWWWGas`.

Jump to

Keyboard shortcuts

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