/secure

🔑 Security utilities, CSP, HPKP, HSTS and other security wins

Primary LanguageGoMIT LicenseMIT

gowww secure GoDoc Build Coverage Go Report Status Testing

Package secure provides security utilities, CSP, HPKP, HSTS and other security wins.

Installing

  1. Get package:

    go get -u github.com/gowww/secure
  2. Import it in your code:

    import "github.com/gowww/secure"

Usage

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.