kos/util/fetch/options.go

51 lines
691 B
Go
Raw Normal View History

2023-04-23 17:57:36 +08:00
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,
}
}