From cbe37a8756408415ff9983027f5c43f99c004bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Fernandes?= Date: Fri, 25 Oct 2024 14:07:18 +0100 Subject: [PATCH] chore(ctxkeys): rename package --- internal/ctx_env/ctx_env.go | 9 --------- internal/ctxkeys/ctxkeys.go | 9 +++++++++ internal/satori/satori.go | 8 ++++---- server/api.go | 14 +++++++------- 4 files changed, 20 insertions(+), 20 deletions(-) delete mode 100644 internal/ctx_env/ctx_env.go create mode 100644 internal/ctxkeys/ctxkeys.go diff --git a/internal/ctx_env/ctx_env.go b/internal/ctx_env/ctx_env.go deleted file mode 100644 index d1e669a45..000000000 --- a/internal/ctx_env/ctx_env.go +++ /dev/null @@ -1,9 +0,0 @@ -package ctx_env - -// Keys used for storing/retrieving user information in the context of a request after authentication. -type CtxUserIDKey struct{} -type CtxUsernameKey struct{} -type CtxVarsKey struct{} -type CtxExpiryKey struct{} -type CtxTokenIDKey struct{} -type CtxTokenIssuedAtKey struct{} diff --git a/internal/ctxkeys/ctxkeys.go b/internal/ctxkeys/ctxkeys.go new file mode 100644 index 000000000..a7d28e170 --- /dev/null +++ b/internal/ctxkeys/ctxkeys.go @@ -0,0 +1,9 @@ +package ctxkeys + +// Keys used for storing/retrieving user information in the context of a request after authentication. +type UserIDKey struct{} +type UsernameKey struct{} +type VarsKey struct{} +type ExpiryKey struct{} +type TokenIDKey struct{} +type TokenIssuedAtKey struct{} diff --git a/internal/satori/satori.go b/internal/satori/satori.go index 7ea495ef9..5179bfb8c 100644 --- a/internal/satori/satori.go +++ b/internal/satori/satori.go @@ -30,7 +30,7 @@ import ( "github.com/golang-jwt/jwt/v4" "github.com/heroiclabs/nakama-common/runtime" - "github.com/heroiclabs/nakama/v3/internal/ctx_env" + "github.com/heroiclabs/nakama/v3/internal/ctxkeys" "go.uber.org/zap" ) @@ -122,9 +122,9 @@ func (stc *sessionTokenClaims) Valid() error { } func (s *SatoriClient) generateToken(ctx context.Context, id string) (string, error) { - tid, _ := ctx.Value(ctx_env.CtxTokenIDKey{}).(string) - tIssuedAt, _ := ctx.Value(ctx_env.CtxTokenIssuedAtKey{}).(int64) - tExpirySec, _ := ctx.Value(ctx_env.CtxExpiryKey{}).(int64) + tid, _ := ctx.Value(ctxkeys.TokenIDKey{}).(string) + tIssuedAt, _ := ctx.Value(ctxkeys.TokenIssuedAtKey{}).(int64) + tExpirySec, _ := ctx.Value(ctxkeys.ExpiryKey{}).(int64) timestamp := time.Now().UTC() if tIssuedAt == 0 && tExpirySec > s.nakamaTokenExpirySec { diff --git a/server/api.go b/server/api.go index 98d326f5c..1f0957fa2 100644 --- a/server/api.go +++ b/server/api.go @@ -39,7 +39,7 @@ import ( grpcgw "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" "github.com/heroiclabs/nakama-common/api" "github.com/heroiclabs/nakama/v3/apigrpc" - "github.com/heroiclabs/nakama/v3/internal/ctx_env" + "github.com/heroiclabs/nakama/v3/internal/ctxkeys" "github.com/heroiclabs/nakama/v3/social" "go.uber.org/zap" "google.golang.org/grpc" @@ -61,12 +61,12 @@ var once sync.Once const byteBracket byte = '{' // Keys used for storing/retrieving user information in the context of a request after authentication. -type ctxUserIDKey = ctx_env.CtxUserIDKey -type ctxUsernameKey = ctx_env.CtxUsernameKey -type ctxVarsKey = ctx_env.CtxVarsKey -type ctxExpiryKey = ctx_env.CtxExpiryKey -type ctxTokenIDKey = ctx_env.CtxTokenIDKey -type ctxTokenIssuedAtKey = ctx_env.CtxTokenIssuedAtKey +type ctxUserIDKey = ctxkeys.UserIDKey +type ctxUsernameKey = ctxkeys.UsernameKey +type ctxVarsKey = ctxkeys.VarsKey +type ctxExpiryKey = ctxkeys.ExpiryKey +type ctxTokenIDKey = ctxkeys.TokenIDKey +type ctxTokenIssuedAtKey = ctxkeys.TokenIssuedAtKey type ctxFullMethodKey struct{}