Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

air-gases/redirector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.