myweb

package
v1.8.7 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrConvertMapStringSlice can not convert to map[string][]string
	ErrConvertMapStringSlice = errors.New("can not convert to map slices of strings")

	// ErrConvertToMapString can not convert to map[string]string
	ErrConvertToMapString = errors.New("can not convert to map of strings")
)
View Source
var (
	HtmlContentType = []string{"text/html; charset=utf-8"}
	JsonContentType = []string{"application/json; charset=utf-8"}
)

Functions

func BindForm

func BindForm[REQ any](req *http.Request, obj *REQ) error

func BindHeader

func BindHeader[REQ any](req *http.Request, obj *REQ) error

func BindJson

func BindJson[REQ any](req *http.Request, obj *REQ) error

func BindPostForm

func BindPostForm[REQ any](req *http.Request, obj *REQ) error

func BindQuery

func BindQuery[REQ any](req *http.Request, obj *REQ) error

func Body

func Body(r *http.Request, w http.ResponseWriter, thenFunc NoReqNoRespService)

func BodyReq

func BodyReq[REQ any](r *http.Request, w http.ResponseWriter, req REQ, thenFunc ReqNoRespService[REQ])

func BodyReqResp

func BodyReqResp[REQ, RESP any](r *http.Request, w http.ResponseWriter, req REQ, thenFunc ServiceFunc[REQ, RESP])

func BodyResp

func BodyResp[RESP any](r *http.Request, w http.ResponseWriter, thenFunc NoReqRespService[RESP])

func Form

func Form(r *http.Request, w http.ResponseWriter, thenFunc NoReqNoRespService)

func FormReq

func FormReq[REQ any](r *http.Request, w http.ResponseWriter, req REQ, thenFunc ReqNoRespService[REQ])

func FormReqResp

func FormReqResp[REQ, RESP any](r *http.Request, w http.ResponseWriter, req REQ, thenFunc ServiceFunc[REQ, RESP])

func FormResp

func FormResp[RESP any](r *http.Request, w http.ResponseWriter, thenFunc NoReqRespService[RESP])

func MapFormWithTag

func MapFormWithTag(ptr any, form map[string][]string, tag string) error

func Query

func Query(r *http.Request, w http.ResponseWriter, thenFunc NoReqNoRespService)

func QueryReq

func QueryReq[REQ any](r *http.Request, w http.ResponseWriter, req REQ, thenFunc ReqNoRespService[REQ])

func QueryReqResp

func QueryReqResp[REQ, RESP any](r *http.Request, w http.ResponseWriter, req REQ, thenFunc ServiceFunc[REQ, RESP])

func QueryResp

func QueryResp[RESP any](r *http.Request, w http.ResponseWriter, thenFunc NoReqRespService[RESP])

func StringToBytes

func StringToBytes(s string) []byte

func WriteBindError

func WriteBindError(w http.ResponseWriter, err error)

func WriteJson

func WriteJson[RESP any](w http.ResponseWriter, httpCode int, resp RESP, err error)

func WriteServiceError

func WriteServiceError(w http.ResponseWriter, err error)

func WriteSuccessJSON

func WriteSuccessJSON(w http.ResponseWriter, data any)

Types

type BindFunc

type BindFunc[REQ any] func(ctx *http.Request, req *REQ) (err error)

参数绑定

type CheckFun

type CheckFun interface {
	Check() error
}

type NoReqNoRespService

type NoReqNoRespService func() error

type NoReqRespService

type NoReqRespService[RESP any] func() (resp RESP, err error)

type PageReq

type PageReq struct {
	Limit int `form:"limit" validate:"min(1,无效的分页数据)"`
	Page  int `form:"page"`
}

-------

type PageResp

type PageResp[T any] struct {
	Total int64 `json:"total"`
	List  []T   `json:"list"`
}

type ReqNoRespService

type ReqNoRespService[REQ any] func(req REQ) error

type ServiceFunc

type ServiceFunc[REQ, RESP any] func(req REQ) (resp RESP, err error)

业务处理

type ValidFunc

type ValidFunc[REQ any] func(req *REQ) (err error)

入参检测

type WriteFunc

type WriteFunc[RESP any] func(w http.ResponseWriter, httpCode int, resp RESP, err error)

写包

Jump to

Keyboard shortcuts

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