redirect

package
v0.0.0-...-e92691c Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2019 License: MIT Imports: 1 Imported by: 0

README

Redirect!

Middleware handler for redirecting http to https

func handle() http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, r.Proto)
		return
	})
}

func main() {
    //OnHTTPS takes bool arg to enable redirect, false in development 
    var redirect = OnHTTPS(true)
    http.Handle("/", redirect(handle()))

    go log.Fatal(http.ListenAndServe(":80", nil))
    log.Fatal(http.ListenAndServeTLS(":443", "cert.pem", "key.pem", nil))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OnHTTPS

func OnHTTPS(enable bool) func(http.Handler) http.Handler

OnHTTPS checks for redirection. Enable is an easy switch for debug/development environments

Types

This section is empty.

Jump to

Keyboard shortcuts

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