option.go 451 B

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