httpcommon

package
v1.1.23 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: LGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TOKEN_EXPIRES  = -20 // token 过期
	RESPONSE_ERROR = -10 // 请求错误
	RESPONSE_OK    = 0   // 请求成功
)

Variables

View Source
var Mux map[string]func(w http.ResponseWriter, r *http.Request)

Functions

func AddRolter

func AddRolter(r string, f func(http.ResponseWriter, *http.Request))

添加路由

func Cors added in v1.0.1

func Cors(w http.ResponseWriter)

func CreateFormRequestBody added in v1.1.22

func CreateFormRequestBody(ds map[string]string, filePath string) (string, io.Reader, error)

返回 Content-Type, body部分 该接口和SendHttpPostFormHeader配合使用

func DefaultQuery

func DefaultQuery(url *url.URL, key, defaultValue string) string

func InitHttpServer

func InitHttpServer(HttpListenPort, HttpsListenPort, CertFile, KeyFile string, backend bool)

func InitHttpServerFile added in v1.1.15

func InitHttpServerFile(HttpListenPort, HttpsListenPort, HttpFilePort, FileRoot, CertFile, KeyFile string, backend bool)

带本地文件服务的接口

func ParseJsonBody

func ParseJsonBody(w http.ResponseWriter, r *http.Request, v interface{}) error

func QueryNum

func QueryNum(url *url.URL, key string) (int, error)

func RemoteIp added in v1.1.9

func RemoteIp(req *http.Request) string

获取请求中的IP

func SendHttpGet

func SendHttpGet(url string, hk, hv []string) (string, error)

func SendHttpGetFile added in v1.1.6

func SendHttpGetFile(url, filepath string, hk, hv []string) error

下载内容到文件

func SendHttpGetFileNoSuffix added in v1.1.12

func SendHttpGetFileNoSuffix(url, filepath string, hk, hv []string) (string, error)

下载内容到文件,文件不带后缀的,需要通过http请求返回的头 找到content-disposition的内容确定后缀

func SendHttpGetHeader added in v1.0.4

func SendHttpGetHeader(url string, hk, hv []string) (string, http.Header, error)

返回数据和头的get请求

func SendHttpGetHeaderBs added in v1.0.9

func SendHttpGetHeaderBs(url string, hk, hv []string) ([]byte, http.Header, error)

返回数据和头的get请求

func SendHttpGetHeaderQ added in v1.0.10

func SendHttpGetHeaderQ(url string, hk, hv []string) (*goquery.Document, http.Header, error)

返回数据和头的get请求

func SendHttpGetQ

func SendHttpGetQ(url string, hk, hv []string) (*goquery.Document, error)

func SendHttpGetTimeout added in v1.1.18

func SendHttpGetTimeout(url string, hk, hv []string, seconds int64) (string, error)

func SendHttpPost

func SendHttpPost(url string, in interface{}) (string, error)

func SendHttpPostBinary added in v1.0.5

func SendHttpPostBinary(url string, in []byte) (string, error)

func SendHttpPostBinaryH added in v1.0.7

func SendHttpPostBinaryH(url string, in []byte, hk []string, hv []string) (string, error)

func SendHttpPostBinaryHeader added in v1.0.8

func SendHttpPostBinaryHeader(url string, in []byte, hk []string, hv []string) (string, http.Header, error)

func SendHttpPostBinaryHeaderB added in v1.0.13

func SendHttpPostBinaryHeaderB(url string, in []byte, hk []string, hv []string) ([]byte, http.Header, error)

func SendHttpPostFormHeader added in v1.1.4

func SendHttpPostFormHeader(url string, in io.Reader, hk []string, hv []string) ([]byte, http.Header, error)

post form-data

func SendHttpPostH added in v1.0.6

func SendHttpPostH(url string, in interface{}, hk []string, hv []string) (string, error)

func SendHttpPut added in v1.1.0

func SendHttpPut(url string, in []byte, hk, hv []string) error

func SendHttpPutHeader added in v1.1.1

func SendHttpPutHeader(url string, in []byte, hk, hv []string) (http.Header, error)

func SendHttpPutHeaderBs added in v1.1.3

func SendHttpPutHeaderBs(url string, in []byte, hk, hv []string) ([]byte, http.Header, error)

func WriteError

func WriteError(w http.ResponseWriter, r *http.Request, rd interface{})

Types

type MyHandler

type MyHandler struct {
}

func (*MyHandler) ServeHTTP

func (lh *MyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ResponDData

type ResponDData struct {
	Time string `json:"time"`
}

type ResponeBase

type ResponeBase struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
}

type ResponeData

type ResponeData struct {
	ResponeBase
	Data ResponDData `json:"data"`
}

Jump to

Keyboard shortcuts

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