http

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: May 10, 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 = "*/*"
)

Variables

This section is empty.

Functions

func Delete

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

func DeleteOfStandard

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

func DeleteSimple

func DeleteSimple(url string) ([]byte, error)

func DeleteSimpleOfStandard

func DeleteSimpleOfStandard(url string) ([]byte, error)

func Get

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

func GetOfStandard

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

func GetSimple

func GetSimple(url string) ([]byte, error)

func GetSimpleOfStandard

func GetSimpleOfStandard(url string) ([]byte, 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) ([]byte, error)

func PatchOfStandard

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

func PatchSimple

func PatchSimple(url string, body any) ([]byte, error)

func PatchSimpleOfStandard

func PatchSimpleOfStandard(url string, body any) ([]byte, error)

func Post

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

func PostOfStandard

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

func PostSimple

func PostSimple(url string, body any) ([]byte, error)

func PostSimpleOfStandard

func PostSimpleOfStandard(url string, body any) ([]byte, error)

func Put

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

func PutOfStandard

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

func PutSimple

func PutSimple(url string, body any) ([]byte, error)

func PutSimpleOfStandard

func PutSimpleOfStandard(url string, body any) ([]byte, 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