You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
511 B
26 lines
511 B
package middleware
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/unrolled/secure"
|
|
)
|
|
|
|
// 用https把这个中间件在router里面use一下就好
|
|
|
|
func LoadTls() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
middleware := secure.New(secure.Options{
|
|
SSLRedirect: true,
|
|
SSLHost: "localhost:443",
|
|
})
|
|
err := middleware.Process(c.Writer, c.Request)
|
|
if err != nil {
|
|
//如果出现错误,请不要继续。
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
// 继续往下处理
|
|
c.Next()
|
|
}
|
|
}
|