Skip to content

Commit

Permalink
feat: map[string]interface{}をClaimsでショートカットする
Browse files Browse the repository at this point in the history
  • Loading branch information
ken109 committed Feb 2, 2021
1 parent 4aa5e6c commit eda4385
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"time"
)

type Claims map[string]interface{}

type Option struct {
privateKey *rsa.PrivateKey
Issuer string
Expand Down Expand Up @@ -85,7 +87,7 @@ func setOption(option Option) {
options = option
}

func GetToken(claims map[string]interface{}) ([]byte, error) {
func GetToken(claims Claims) ([]byte, error) {
var err error

t := jwt.New()
Expand Down Expand Up @@ -143,9 +145,9 @@ func Verify(c *gin.Context) {
return
}

func GetClaims(c *gin.Context) map[string]interface{} {
func GetClaims(c *gin.Context) Claims {
if claims, ok := c.Get("claims"); ok {
return claims.(map[string]interface{})
return claims.(Claims)
} else {
return nil
}
Expand Down

0 comments on commit eda4385

Please sign in to comment.