option.go 427 B

123456789101112131415161718192021
  1. package middleware
  2. import "context"
  3. type Option struct {
  4. GenHttp bool
  5. NotAuth bool
  6. OperationRecord bool
  7. Path string
  8. }
  9. type httpOption struct{}
  10. func NewOptionContext(ctx context.Context, op *Option) context.Context {
  11. return context.WithValue(ctx, httpOption{}, op)
  12. }
  13. func FromOptionContext(ctx context.Context) (*Option, bool) {
  14. op, ok := ctx.Value(httpOption{}).(*Option)
  15. return op, ok
  16. }