Package secure provides security utilities, CSP, HPKP, HSTS and other security wins.
-
Get package:
go get -u github.com/gowww/secure
-
Import it in your code:
import "github.com/gowww/secure"
To wrap an http.Handler, use Handle:
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello")
})
http.ListenAndServe(":8080", secure.Handle(mux, nil))
To wrap an http.HandlerFunc, use HandleFunc:
http.Handle("/", secure.HandleFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello")
}, nil))
http.ListenAndServe(":8080", nil)
To set custom security options, see Options GoDoc reference.