http

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2021 License: MIT Imports: 15 Imported by: 0

README

HTTP

QueryBinding

Request

Example:

package main

import (
    "fmt"
    "net/url"
    
    "github.com/QisFj/godry/http"
)

func main(){
    var req interface{}     // request body = json.Marshal(req)
    var resp interface{}    // json.Unmarshal(response body, &resp)
    err := new(http.Request).With(
        http.POST{},
        http.StatusCodeCheck{
            // if status code != 200 ; return error
            Equal:200,
        },
    ).Do("http://example.com", url.Values{
        "params": {"1", "2"},
    }, req, &resp)
    if err != nil {
        fmt.Println(err)
        return 
    }
    fmt.Printf("Resp: %#v\n", resp)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Binding

type Binding interface {
	Bind(*http.Request, interface{}) error
}

type BindingFunc

type BindingFunc func(*http.Request, interface{}) error

func (BindingFunc) Bind

func (f BindingFunc) Bind(r *http.Request, v interface{}) error

type Client

type Client struct {
	Client *http.Client
	// contains filtered or unexported fields
}

func (Client) On

func (opt Client) On(r *Request)
type Header struct {
	Key, Value string
	// contains filtered or unexported fields
}

func (Header) On

func (opt Header) On(r *Request)

type Log

type Log struct {
	Logger            func(format string, v ...interface{})
	URL               bool
	RequestBody       bool
	RequestBodyLimit  int
	ResponseBody      bool
	ResponseBodyLimit int
	// contains filtered or unexported fields
}

func (Log) On

func (opt Log) On(r *Request)

type POST

type POST struct {
	// contains filtered or unexported fields
}

func (POST) On

func (opt POST) On(r *Request)

type QueryBinding

type QueryBinding struct {
	Validate ValidateFunc
}

func (QueryBinding) Bind

func (b QueryBinding) Bind(r *http.Request, v interface{}) (err error)

type Request

type Request struct {
	// contains filtered or unexported fields
}

func (Request) Do

func (r Request) Do(u string, v url.Values, req, resp interface{}) error

Do request with default context

func (Request) DoCtx

func (r Request) DoCtx(ctx context.Context, u string, v url.Values, req, resp interface{}) error

Do request

func (*Request) With

func (r *Request) With(opts ...RequestOpt) *Request

type RequestOpt

type RequestOpt interface {
	On(r *Request)
	// contains filtered or unexported methods
}

type ResponseCheck

type ResponseCheck func(response []byte) error

func (ResponseCheck) On

func (opt ResponseCheck) On(r *Request)

type ResponseCheckAfterUnmarshal

type ResponseCheckAfterUnmarshal func(response interface{}) error

func (ResponseCheckAfterUnmarshal) On

type StatusCodeCheck

type StatusCodeCheck struct {

	// only one of Equal and CheckFunc will take effect
	// if set many StatusCodeCheck options, all of them must be passed
	Equal     int
	CheckFunc func(statusCode int) error
	// contains filtered or unexported fields
}

func (StatusCodeCheck) On

func (opt StatusCodeCheck) On(r *Request)

type Timeout

type Timeout time.Duration

func (Timeout) On

func (opt Timeout) On(r *Request)

type ValidateFunc

type ValidateFunc func(v interface{}) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL