Documentation ¶
Index ¶
- type ClientRequest
- func (r ClientRequest) HTTP() (httpRequest *http.Request, err error)
- func (r ClientRequest) Header(value ...RValue) ClientRequest
- func (r ClientRequest) Query(value ...RValue) ClientRequest
- func (r ClientRequest) SetBasicAuth(username, password string) ClientRequest
- func (r ClientRequest) SetBody(data interface{}) ClientRequest
- func (r ClientRequest) URI(path string, a ...interface{}) ClientRequest
- type Encoder
- type Middleware
- type Option
- type RValue
- type Values
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientRequest ¶
type ClientRequest struct { Encoder Encoder Method string Path string PathArgs []interface{} Body io.Reader // contains filtered or unexported fields }
ClientRequest make request by params method query
func NewGet ¶
func NewGet(ctx context.Context, opts ...Option) ClientRequest
NewGet create new get request
func NewPost ¶
func NewPost(ctx context.Context, opts ...Option) ClientRequest
NewPost create new post request
func NewRequest ¶
func NewRequest(ctx context.Context, opts ...Option) ClientRequest
NewRequest create new request
func (ClientRequest) HTTP ¶
func (r ClientRequest) HTTP() (httpRequest *http.Request, err error)
HTTP create http Request
func (ClientRequest) Header ¶
func (r ClientRequest) Header(value ...RValue) ClientRequest
Header add values for the header
func (ClientRequest) Query ¶
func (r ClientRequest) Query(value ...RValue) ClientRequest
Query add values for the qu
Example ¶
ctx := context.TODO() req, err := NewRequest(ctx, WithEncoder(clientEncoder)). Query( StringValue("q", "search"), Int64Value("id", 2), TimeValue("ts", time.Now(), time.RFC3339Nano), ). HTTP() if err != nil { log.Fatal(err) } res, err := http.DefaultClient.Do(req) if err != nil { log.Fatal(err) } defer res.Body.Close() fmt.Println(res.Body)
Output:
func (ClientRequest) SetBasicAuth ¶
func (r ClientRequest) SetBasicAuth(username, password string) ClientRequest
SetBasicAuth set username and password basic auth
func (ClientRequest) SetBody ¶
func (r ClientRequest) SetBody(data interface{}) ClientRequest
SetBody encode body and add to request
func (ClientRequest) URI ¶
func (r ClientRequest) URI(path string, a ...interface{}) ClientRequest
URI set url and args it
type Middleware ¶
type Middleware func(ctx context.Context, cr *ClientRequest, n func(context.Context) (*http.Request, error)) (*http.Request, error)
Middleware handle middleware
type Option ¶
type Option func(*ClientRequest)
Option configure client request
func WithMiddleware ¶
func WithMiddleware(mw ...Middleware) Option
WithMiddleware set middleware request
Click to show internal directories.
Click to hide internal directories.