ctxdata.go 696 B

12345678910111213141516171819202122232425262728293031323334
  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 GetTraceIdFromCtx(ctx context.Context) string {
  23. spanCtx := trace.SpanContextFromContext(ctx)
  24. if spanCtx.HasTraceID() {
  25. return spanCtx.TraceID().String()
  26. }
  27. return ""
  28. }