http

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2022 License: Apache-2.0 Imports: 10 Imported by: 3

README

http

http包是简化封装解析,在公司这边有标准的返回结构,但是我们很多时候只使用其中的data部分,很多时候自己需要判断并解析,这里对这个做了简单的工具封装

{
  "code": 0,
  "message": "yy",
  "data": "xx"
}

示例

func TestGetSimple(t *testing.T) {
    // {"code":"success","data":"ok","message":"成功"}
    data, err := http.GetSimple("http://localhost:8082/api/api/app/sample/test/get")
    if err != nil {
        fmt.Errorf(err.Error())
        return
    }
    fmt.Println(string(data))

    // "ok"
    data, err = http.GetSimpleOfStandard("http://localhost:8082/api/api/app/sample/test/get")
    if err != nil {
        fmt.Errorf(err.Error())
        return
    }
    fmt.Println(string(data))
}

Documentation

Index

Constants

View Source
const (
	MaxIdleConns          int    = 100
	MaxIdleConnsPerHost   int    = 100
	IdleConnTimeout       int    = 90
	ContentTypeJson       string = "application/json; charset=utf-8"
	ContentTypeHtml       string = "text/html; charset=utf-8"
	ContentTypeText       string = "text/plain; charset=utf-8"
	ContentTypeCss        string = "text/css; charset=utf-8"
	ContentTypeJavaScript string = "application/x-javascript; charset=utf-8"
	ContentTypeJpeg       string = "image/jpeg"
	ContentTypePng        string = "image/png"
	ContentTypeGif        string = "image/gif"
	ContentTypeAll        string = "*/*"
	ContentPostForm       string = "application/x-www-form-urlencoded"
)

Variables

This section is empty.

Functions

func Delete

func Delete(url string, header http.Header, parameterMap map[string]string) (int, http.Header, any, error)

func DeleteOfStandard

func DeleteOfStandard(url string, header http.Header, parameterMap map[string]string) (int, http.Header, any, error)

func DeleteSimple

func DeleteSimple(url string) (int, http.Header, any, error)

func DeleteSimpleOfStandard

func DeleteSimpleOfStandard(url string) (int, http.Header, any, error)

func Get

func Get(url string, header http.Header, parameterMap map[string]string) (int, http.Header, any, error)

func GetClient added in v1.3.0

func GetClient() *http.Client

func GetOfStandard

func GetOfStandard(url string, header http.Header, parameterMap map[string]string) (int, http.Header, any, error)

func GetSimple

func GetSimple(url string) (int, http.Header, any, error)

func GetSimpleOfStandard

func GetSimpleOfStandard(url string) (int, http.Header, any, error)
func Head(url string, header http.Header, parameterMap map[string]string) error

func HeadSimple

func HeadSimple(url string) error

func Patch

func Patch(url string, header http.Header, parameterMap map[string]string, body any) (int, http.Header, any, error)

func PatchOfStandard

func PatchOfStandard(url string, header http.Header, parameterMap map[string]string, body any) (int, http.Header, any, error)

func PatchSimple

func PatchSimple(url string, body any) (int, http.Header, any, error)

func PatchSimpleOfStandard

func PatchSimpleOfStandard(url string, body any) (int, http.Header, any, error)

func Post

func Post(url string, header http.Header, parameterMap map[string]string, body any) (int, http.Header, any, error)

func PostForm added in v1.1.0

func PostForm(url string, header http.Header, parameterMap map[string]any) (int, http.Header, any, error)

func PostOfStandard

func PostOfStandard(url string, header http.Header, parameterMap map[string]string, body any) (int, http.Header, any, error)

func PostSimple

func PostSimple(url string, body any) (int, http.Header, any, error)

func PostSimpleOfStandard

func PostSimpleOfStandard(url string, body any) (int, http.Header, any, error)

func Put

func Put(url string, header http.Header, parameterMap map[string]string, body any) (int, http.Header, any, error)

func PutOfStandard

func PutOfStandard(url string, header http.Header, parameterMap map[string]string, body any) (int, http.Header, any, error)

func PutSimple

func PutSimple(url string, body any) (int, http.Header, any, error)

func PutSimpleOfStandard

func PutSimpleOfStandard(url string, body any) (int, http.Header, any, error)

func SetHttpClient

func SetHttpClient(httpClientOuter *http.Client)

Types

type DataResponse

type DataResponse[T any] struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    T      `json:"data"`
}

type NetError

type NetError struct {
	ErrMsg string
}

func (*NetError) Error

func (error *NetError) Error() string

Jump to

Keyboard shortcuts

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