credentials.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright 2021 gRPC authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package credentials
  17. import (
  18. "context"
  19. )
  20. // requestInfoKey is a struct to be used as the key to store RequestInfo in a
  21. // context.
  22. type requestInfoKey struct{}
  23. // NewRequestInfoContext creates a context with ri.
  24. func NewRequestInfoContext(ctx context.Context, ri any) context.Context {
  25. return context.WithValue(ctx, requestInfoKey{}, ri)
  26. }
  27. // RequestInfoFromContext extracts the RequestInfo from ctx.
  28. func RequestInfoFromContext(ctx context.Context) any {
  29. return ctx.Value(requestInfoKey{})
  30. }
  31. // clientHandshakeInfoKey is a struct used as the key to store
  32. // ClientHandshakeInfo in a context.
  33. type clientHandshakeInfoKey struct{}
  34. // ClientHandshakeInfoFromContext extracts the ClientHandshakeInfo from ctx.
  35. func ClientHandshakeInfoFromContext(ctx context.Context) any {
  36. return ctx.Value(clientHandshakeInfoKey{})
  37. }
  38. // NewClientHandshakeInfoContext creates a context with chi.
  39. func NewClientHandshakeInfoContext(ctx context.Context, chi any) context.Context {
  40. return context.WithValue(ctx, clientHandshakeInfoKey{}, chi)
  41. }