You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
915 B
Go
40 lines
915 B
Go
package httpc
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
)
|
|
|
|
type (
|
|
Service interface {
|
|
Do(r *http.Request, opts ...Option) (*http.Response, error)
|
|
Get(url string, opts ...Option) (*http.Response, error)
|
|
Post(url, contentType string, body io.Reader, opts ...Option) (*http.Response, error)
|
|
}
|
|
|
|
namedService struct {
|
|
name string
|
|
opts []Option
|
|
}
|
|
)
|
|
|
|
func NewService(name string, opts ...Option) Service {
|
|
return namedService{
|
|
name: name,
|
|
opts: opts,
|
|
}
|
|
}
|
|
|
|
func (s namedService) Do(r *http.Request, opts ...Option) (*http.Response, error) {
|
|
return Do(s.name, r, append(s.opts, opts...)...)
|
|
}
|
|
|
|
func (s namedService) Get(url string, opts ...Option) (*http.Response, error) {
|
|
return Get(s.name, url, append(s.opts, opts...)...)
|
|
}
|
|
|
|
func (s namedService) Post(url, contentType string, body io.Reader, opts ...Option) (
|
|
*http.Response, error) {
|
|
return Post(s.name, url, contentType, body, append(s.opts, opts...)...)
|
|
}
|