valueonlycontext.go 490 B

1234567891011121314151617181920212223242526272829
  1. package contextx
  2. import (
  3. "context"
  4. "time"
  5. )
  6. type valueOnlyContext struct {
  7. context.Context
  8. }
  9. func (valueOnlyContext) Deadline() (deadline time.Time, ok bool) {
  10. return
  11. }
  12. func (valueOnlyContext) Done() <-chan struct{} {
  13. return nil
  14. }
  15. func (valueOnlyContext) Err() error {
  16. return nil
  17. }
  18. // ValueOnlyFrom takes all values from the given ctx, without deadline and error control.
  19. func ValueOnlyFrom(ctx context.Context) context.Context {
  20. return valueOnlyContext{
  21. Context: ctx,
  22. }
  23. }