options.go 691 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package fetch
  2. import "net/http"
  3. type (
  4. Options struct {
  5. Url string
  6. Method string
  7. Header map[string]string
  8. Params map[string]string
  9. Data any
  10. }
  11. Option func(o *Options)
  12. )
  13. func WithUrl(s string) Option {
  14. return func(o *Options) {
  15. o.Url = s
  16. }
  17. }
  18. func WithMethod(s string) Option {
  19. return func(o *Options) {
  20. o.Method = s
  21. }
  22. }
  23. func WithHeader(h map[string]string) Option {
  24. return func(o *Options) {
  25. o.Header = h
  26. }
  27. }
  28. func WithParams(h map[string]string) Option {
  29. return func(o *Options) {
  30. o.Params = h
  31. }
  32. }
  33. func WithData(v any) Option {
  34. return func(o *Options) {
  35. o.Data = v
  36. }
  37. }
  38. func newOptions() *Options {
  39. return &Options{
  40. Method: http.MethodGet,
  41. }
  42. }