Documentation ¶
Overview ¶
Package requestdecorator provides helper functions to decorate a request with user agent versions, auth, meta headers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrNilRequest = errors.New("request cannot be nil")
)
Functions ¶
This section is empty.
Types ¶
type AuthDecorator ¶
type AuthDecorator struct {
// contains filtered or unexported fields
}
func (*AuthDecorator) ChangeRequest ¶
type Decorator ¶
type Decorator interface { // ChangeRequest() changes the request accordingly. // The changed request will be returned or err will be non-nil // if an error occur. ChangeRequest(req *http.Request) (newReq *http.Request, err error) }
Decorator is used to change an instance of http.Request. It could be used to add more header fields, change body, etc.
func NewAuthDecorator ¶
type MetaHeadersDecorator ¶
func (*MetaHeadersDecorator) ChangeRequest ¶
type RequestFactory ¶
type RequestFactory struct {
// contains filtered or unexported fields
}
RequestFactory creates an HTTP request and applies a list of decorators on the request.
func NewRequestFactory ¶
func NewRequestFactory(d ...Decorator) *RequestFactory
func (*RequestFactory) AddDecorator ¶
func (f *RequestFactory) AddDecorator(d ...Decorator)
func (*RequestFactory) GetDecorators ¶
func (f *RequestFactory) GetDecorators() []Decorator
func (*RequestFactory) NewRequest ¶
func (h *RequestFactory) NewRequest(method, urlStr string, body io.Reader, d ...Decorator) (*http.Request, error)
NewRequest() creates a new *http.Request, applies all decorators in the Factory on the request, then applies decorators provided by d on the request.
type UAVersionInfo ¶
UAVersionInfo is used to model UserAgent versions.
func NewUAVersionInfo ¶
func NewUAVersionInfo(name, version string) UAVersionInfo
type UserAgentDecorator ¶
type UserAgentDecorator struct {
Versions []UAVersionInfo
}
UserAgentDecorator appends the product/version to the user agent field of a request.
func (*UserAgentDecorator) ChangeRequest ¶
Click to show internal directories.
Click to hide internal directories.