123456789101112131415161718192021222324252627 |
- package biz
- import (
- "context"
- "github.com/go-kratos/kratos/v2/middleware/auth/jwt"
- jwt2 "github.com/golang-jwt/jwt/v5"
- "github.com/google/uuid"
- )
- // getIdByContext returns the ID from the context.
- func getIdByContext(ctx context.Context) string {
- token, ok := jwt.FromContext(ctx)
- if ok {
- mapClaims := token.(*jwt2.MapClaims)
- id := (*mapClaims)["id"].(string)
- return id
- }
- panic("get id from context failed")
- }
- func newUUID() uuid.UUID {
- id, err := uuid.NewV7()
- if err != nil {
- panic("new uuid failed")
- }
- return id
- }
|