| 1 | /*Package secure is an HTTP middleware for Go that facilitates some quick security wins. |
| 2 | |
| 3 | package main |
| 4 | |
| 5 | import ( |
| 6 | "net/http" |
| 7 | |
| 8 | "github.com/unrolled/secure" // or "gopkg.in/unrolled/secure.v1" |
| 9 | ) |
| 10 | |
| 11 | var myHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 12 | w.Write([]byte("hello world")) |
| 13 | }) |
| 14 | |
| 15 | func main() { |
| 16 | secureMiddleware := secure.New(secure.Options{ |
| 17 | AllowedHosts: []string{"www.example.com", "sub.example.com"}, |
| 18 | SSLRedirect: true, |
| 19 | }) |
| 20 | |
| 21 | app := secureMiddleware.Handler(myHandler) |
| 22 | http.ListenAndServe("127.0.0.1:3000", app) |
| 23 | } |
| 24 | */ |
| 25 | package secure |