ctxdata.go 813 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. //@File ctxdata.go
  2. //@Time 2022/04/27
  3. //@Author #Suyghur,
  4. package ctxdata
  5. import (
  6. "context"
  7. "go.opentelemetry.io/otel/trace"
  8. "ylink/comm/jwtkey"
  9. )
  10. func GetPlayerIdFromCtx(ctx context.Context) string {
  11. playerId, _ := ctx.Value(jwtkey.PlayerId).(string)
  12. return playerId
  13. }
  14. func GetGameIdFromCtx(ctx context.Context) string {
  15. gameId, _ := ctx.Value(jwtkey.GameId).(string)
  16. return gameId
  17. }
  18. func GetCsIdFromCtx(ctx context.Context) string {
  19. csId, _ := ctx.Value(jwtkey.CsId).(string)
  20. return csId
  21. }
  22. func GetConnectTypeFromCtx(ctx context.Context) int32 {
  23. cType, _ := ctx.Value(jwtkey.Type).(int32)
  24. return cType
  25. }
  26. func GetTraceIdFromCtx(ctx context.Context) string {
  27. spanCtx := trace.SpanContextFromContext(ctx)
  28. if spanCtx.HasTraceID() {
  29. return spanCtx.TraceID().String()
  30. }
  31. return ""
  32. }