Skip to content

Commit 240f307

Browse files
committed
refactor: switch NewRBACClaims to return value type instead of pointer
- Update `NewRBACClaims` to return struct value types to improve safety and simplify usage. - Adjust `jwt_test.go` to align with the updated function signature. Signed-off-by: tbxark <tbxark@outlook.com>
1 parent a8c9a0f commit 240f307

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

server/auth/jwtauth/claims.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ type RBACClaims[T authorizer.UID] struct {
1515
Roles []string `json:"roles,omitempty"`
1616
}
1717

18-
func NewRBACClaims[T authorizer.UID](uid T, subject string, roles []string, expiresAt time.Time) *RBACClaims[T] {
19-
return &RBACClaims[T]{
18+
func NewRBACClaims[T authorizer.UID](uid T, subject string, roles []string, expiresAt time.Time) RBACClaims[T] {
19+
return RBACClaims[T]{
2020
RegisteredClaims: jwt.RegisteredClaims{
2121
Subject: subject,
2222
ExpiresAt: jwt.NewNumericDate(expiresAt),

server/auth/jwtauth/jwt_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func TestJwtAuth_GenerateToken(t *testing.T) {
12-
claims := *NewRBACClaims[int64](12345, "test-subject", []string{"admin", "user"}, time.Now().Add(1*time.Hour))
12+
claims := NewRBACClaims[int64](12345, "test-subject", []string{"admin", "user"}, time.Now().Add(1*time.Hour))
1313
jwtAuth := NewJwtAuth[RBACClaims[int64]]("secret")
1414
token, err := jwtAuth.GenerateToken(context.Background(), claims)
1515
if err != nil {

0 commit comments

Comments
 (0)