xhttp

package
v0.0.0-...-7c3cb44 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ConContent-Type
	ConContentType           string = "ConContent-Type"
	ConContentTypeJson       string = "application/json; charset=utf-8"
	ConContentTypeJavaScript string = "application/x-javascript;charset=UTF-8"

	// Connection
	Connection          string = "Connection"
	ConnectionKeepAlive string = "keep-alive"

	// Accept-Language
	AcceptLanguage     string = "Accept-Language"
	AcceptLanguageZhCN string = "zh-CN,zh;q=0.9"

	// Accept-Encoding
	AcceptEncoding        string = "Accept-Language"
	AcceptEncodingGzip    string = "gzip"
	AcceptEncodingDeflate string = "deflate"
	AcceptEncodingBr      string = "br"
	AcceptEncodingDefault string = "gzip, deflate, br"

	// User-Agent
	UserAgent                          string = "User-Agent"
	UserAgentWindowsChrome93_0_4577_63 string = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36"
	UserAgentWindowsFirefox92_0        string = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0"
)

Variables

View Source
var DefaultClient = &http.Client{}

Functions

func AssetHandler

func AssetHandler(prefix, root, indexFile string, assets embed.FS) http.Handler

AssetHandler 返回一个 http.Handler ,它将从 资产嵌入.FS。定位文件时,它将删除给定的 请求中的前缀并将根添加到文件系统中 查找:典型的前缀可能是 /web/,而 root 将被构建。

func Do

func Do(req *http.Request, resp func(*http.Response) error) (err error)

func FileServer

func FileServer(port, prefix, root, indexFile string, assets embed.FS) error

FileServer web server

func Get

func Get(url string, resp func(*http.Response) error) (err error)

func JsonUnmarshalResponse

func JsonUnmarshalResponse(resp interface{}, body []byte) error

func MainDomain

func MainDomain(domain string) string

func Publicsuffix

func Publicsuffix(domain string) string

Types

type Request

type Request struct {
	*http.Request
}

func NewRequest

func NewRequest(req *http.Request) *Request

func (*Request) GetQueryInt

func (req *Request) GetQueryInt(key string) int

func (*Request) GetQueryInt_

func (req *Request) GetQueryInt_(key string) *int

func (*Request) GetQueryString

func (req *Request) GetQueryString(key string) string

func (*Request) GetQueryString_

func (req *Request) GetQueryString_(key string) *string

type Resp

type Resp struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg,omitempty"`
	Err  string      `json:"err,omitempty"`
	Data interface{} `json:"data,omitempty"`
}

type Response

type Response struct {
	http.ResponseWriter
}

func NewResponse

func NewResponse(w http.ResponseWriter) *Response

func (*Response) JSON

func (r *Response) JSON(body interface{}) error

func (*Response) JSONP

func (r *Response) JSONP(callbackFunc string, body interface{}) error

func (*Response) JSONResp

func (r *Response) JSONResp(body *Resp) error

func (*Response) JSONRespWithStatus

func (r *Response) JSONRespWithStatus(statusCode int, body *Resp) error

func (*Response) JSONWithStatus

func (r *Response) JSONWithStatus(statusCode int, body interface{}) error

Jump to

Keyboard shortcuts

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