forked from open-kingfisher/king-kf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.go
35 lines (33 loc) · 855 Bytes
/
token.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package user
import (
jwt "github.com/dgrijalva/jwt-go"
"github.com/gin-gonic/gin"
"github.com/duiniwukenaihe/king-utils/common"
jwtAuth "github.com/duiniwukenaihe/king-utils/middleware/jwt"
"net/http"
"time"
)
func GetToken(c *gin.Context) {
responseData := common.ResponseData{}
j := &jwtAuth.JWT{
SigningKey: []byte(common.Signing),
}
claims := jwtAuth.CustomClaims{
ID: "1",
Name: "Tom",
Email: "tom@kingfisher.com",
StandardClaims: jwt.StandardClaims{
ExpiresAt: time.Now().Add(common.ExpiresAt).Unix(),
},
}
if token, err := j.CreateToken(claims); err == nil {
responseData.Msg = ""
responseData.Data = token
responseData.Code = http.StatusOK
} else {
responseData.Msg = err.Error()
responseData.Data = ""
responseData.Code = http.StatusInternalServerError
}
c.JSON(responseData.Code, responseData)
}