51 lines
691 B
Go
51 lines
691 B
Go
|
package fetch
|
||
|
|
||
|
import "net/http"
|
||
|
|
||
|
type (
|
||
|
Options struct {
|
||
|
Url string
|
||
|
Method string
|
||
|
Header map[string]string
|
||
|
Params map[string]string
|
||
|
Data any
|
||
|
}
|
||
|
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) {
|
||
|
o.Header = h
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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,
|
||
|
}
|
||
|
}
|