...

Source file src/github.com/gin-contrib/secure/example/code1/example.go

Documentation: github.com/gin-contrib/secure/example/code1

     1  package main
     2  
     3  import (
     4  	"github.com/gin-contrib/secure"
     5  	"github.com/gin-gonic/gin"
     6  )
     7  
     8  func main() {
     9  	router := gin.Default()
    10  
    11  	router.Use(secure.New(secure.Config{
    12  		AllowedHosts:          []string{"example.com", "ssl.example.com"},
    13  		SSLRedirect:           true,
    14  		SSLHost:               "ssl.example.com",
    15  		STSSeconds:            315360000,
    16  		STSIncludeSubdomains:  true,
    17  		FrameDeny:             true,
    18  		ContentTypeNosniff:    true,
    19  		BrowserXssFilter:      true,
    20  		ContentSecurityPolicy: "default-src 'self'",
    21  		IENoOpen:              true,
    22  		ReferrerPolicy:        "strict-origin-when-cross-origin",
    23  		SSLProxyHeaders:       map[string]string{"X-Forwarded-Proto": "https"},
    24  	}))
    25  
    26  	router.GET("/ping", func(c *gin.Context) {
    27  		c.String(200, "pong")
    28  	})
    29  
    30  	// Listen and Server in 0.0.0.0:8080
    31  	router.Run()
    32  }
    33  

View as plain text