hanayo/vendor/github.com/gin-gonic/contrib/secure/example/example.go

33 lines
766 B
Go
Raw Normal View History

2019-02-23 13:29:15 +00:00
package main
import (
"fmt"
"github.com/gin-gonic/contrib/secure"
"github.com/gin-gonic/gin"
"time"
)
func main() {
r := gin.Default()
r.Use(secure.Secure(secure.Options{
AllowedHosts: []string{"example.com", "ssl.example.com"},
SSLRedirect: true,
SSLHost: "ssl.example.com",
SSLProxyHeaders: map[string]string{"X-Forwarded-Proto": "https"},
STSSeconds: 315360000,
STSIncludeSubdomains: true,
FrameDeny: true,
ContentTypeNosniff: true,
BrowserXssFilter: true,
ContentSecurityPolicy: "default-src 'self'",
}))
r.GET("/ping", func(c *gin.Context) {
c.String(200, "pong "+fmt.Sprint(time.Now().Unix()))
})
// Listen and Server in 0.0.0.0:8080
r.Run(":8080")
}