1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package fetch
- import "net/http"
- type (
- Options struct {
- Url string
- Method string
- Header map[string]string
- Params map[string]string
- Data any
- Human bool
- }
- Option func(o *Options)
- )
- func WithUrl(s string) Option {
- return func(o *Options) {
- o.Url = s
- }
- }
- func WithMethod(s string) Option {
- return func(o *Options) {
- o.Method = s
- }
- }
- func WithHeader(h map[string]string) Option {
- return func(o *Options) {
- if o.Header == nil {
- o.Header = h
- }
- for k, v := range o.Header {
- o.Header[k] = v
- }
- }
- }
- func WithHuman() Option {
- return func(o *Options) {
- o.Human = true
- }
- }
- func WithParams(h map[string]string) Option {
- return func(o *Options) {
- o.Params = h
- }
- }
- func WithData(v any) Option {
- return func(o *Options) {
- o.Data = v
- }
- }
- func newOptions() *Options {
- return &Options{
- Method: http.MethodGet,
- }
- }
|