Skip to content

Commit

Permalink
添加登录超时时间传参设置
Browse files Browse the repository at this point in the history
  • Loading branch information
Jrohy committed Oct 21, 2021
1 parent bb0be7e commit dedfd13
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
)

var (
host string
port int
ssl bool
host string
port int
ssl bool
Timeout int
)

// webCmd represents the web command
Expand All @@ -24,5 +25,6 @@ func init() {
webCmd.Flags().StringVarP(&host, "host", "", "0.0.0.0", "web服务监听地址")
webCmd.Flags().IntVarP(&port, "port", "p", 80, "web服务启动端口")
webCmd.Flags().BoolVarP(&ssl, "ssl", "", false, "web服务是否以https方式运行")
webCmd.Flags().IntVarP(&Timeout, "timeout", "t", 120, "登录超时时间(min)")
rootCmd.AddCommand(webCmd)
}
5 changes: 3 additions & 2 deletions web/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/appleboy/gin-jwt/v2"
"github.com/gin-gonic/gin"
"time"
"trojan/cmd"
"trojan/core"
"trojan/web/controller"
)
Expand All @@ -25,8 +26,8 @@ func init() {
authMiddleware, err = jwt.New(&jwt.GinJWTMiddleware{
Realm: "k8s-manager",
Key: []byte("secret key"),
Timeout: time.Hour,
MaxRefresh: time.Hour,
Timeout: time.Minute * time.Duration(cmd.Timeout),
MaxRefresh: time.Minute * time.Duration(cmd.Timeout),
IdentityKey: identityKey,
SendCookie: true,
PayloadFunc: func(data interface{}) jwt.MapClaims {
Expand Down

0 comments on commit dedfd13

Please sign in to comment.