A useful gas that used to redirect unintended requests for the web applications built using Air.
Open your terminal and execute
$ go get github.com/air-gases/redirector
done.
The only requirement is the Go, at least v1.13.
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()
}
If you want to discuss Redirector, or ask questions about it, simply post questions or ideas here.
If you want to help build Redirector, simply follow this to send pull requests here.
This project is licensed under the MIT License.
License can be found here.