httpgo

package module
v0.0.0-...-863588f Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 9 Imported by: 0

README

httpgo

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// BusinessCodeOK represents the business code for success.
	BusinessCodeOK = 0
	// BusinessMsgOK represents the business message for success.
	BusinessMsgOK = "ok"
	// BusinessCodeError represents the business code for error.
	BusinessCodeError = -1

	ResponseContentTypeJSON = "application/json"
	ResponseContentTypeXML  = "application/xml"
)
View Source
var (
	CompileIsScript = []string{
		"curl",
		"wget",
		"collectd",
		"python",
		"urllib",
		"java",
		"jakarta",
		"httpclient",
		"phpcrawl",
		"libwww",
		"perl",
		"go-http",
		"okhttp",
		"lua-resty",
		"winhttp",
		"awesomium",
	}
)

Functions

func Bind

func Bind(req *http.Request, obj any, binding binding.Binding) error

func DefaultBind

func DefaultBind(req *http.Request, obj any) error

func IsAjax

func IsAjax(req *http.Request) bool

func IsSSL

func IsSSL(req *http.Request) bool

func IsScript

func IsScript(req *http.Request) bool

func JSONResponse

func JSONResponse(w http.ResponseWriter, code int, v any) error

func JSONResponseWithCode

func JSONResponseWithCode(w http.ResponseWriter, code int, v any) error

JSONResponseWithCode writes v as json string into w with code.

func OKJSONResponse

func OKJSONResponse(w http.ResponseWriter, v any) error

OKJSONResponse writes v into w with http.StatusOK.

func OKResponse

func OKResponse(w http.ResponseWriter)

OKResponse writes HTTP 200 OK into w.

func OKXMLResponse

func OKXMLResponse(w http.ResponseWriter, v any) error

OKXMLResponse writes v into w with http.StatusOK.

func XMLResponse

func XMLResponse(w http.ResponseWriter, code int, v any) error

func XMLResponseWithCode

func XMLResponseWithCode(w http.ResponseWriter, code int, v any) error

XMLResponseWithCode writes v as xml string into w with code.

Types

type BaseResponse

type BaseResponse[T any] struct {
	// Code represents the business code, not the http status code.
	Code int `json:"code" xml:"code"`
	// Msg represents the business message, if Code = BusinessCodeOK,
	// and Msg is empty, then the Msg will be set to BusinessMsgSuccess.
	Msg string `json:"msg" xml:"msg"`
	// Data represents the business data.
	Data T `json:"data,omitempty" xml:"data,omitempty"`
}

BaseResponse is the base response struct.

type BaseResponseErr

type BaseResponseErr interface {
	error
	Code() int
}

Directories

Path Synopsis
t

Jump to

Keyboard shortcuts

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