cc

package
v0.0.0-...-a1b16c7 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: MIT Imports: 18 Imported by: 0

README

cc

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ContentType map[string]string

	ActionGroups map[string]ActionGroup
)

Functions

func AddActionGroup

func AddActionGroup(groupPath string, actionFunc ActionGroupFunc)

添加一个业务逻辑组 所有的 action 将在 RegisterActions() 被调用时启用

func AddActionGroupDeprecated

func AddActionGroupDeprecated(groupPath string, actionFunc ActionGroupFunc)

func ErrorFetcher

func ErrorFetcher() middleware.MiddewareFunc

异常捕捉

func Get

func Get(url string) (respStr string, e error)

http get request

func GetByProxy

func GetByProxy(webUrl, proxyUrl string) (respStr string, e error)

func GetJ

func GetJ(url string, v interface{}) (e error)

http get request with json

func HerArgInvalid

func HerArgInvalid(argName string) (HttpErrReturn, StatusCode)

func HerData

func HerData(str string) (HttpErrReturn, StatusCode)

http仅返回data,兼容resp

func HerDeprecated

func HerDeprecated() (HttpErrReturn, StatusCode)

用于在弃用的API中直接返回 请使用( a ActionGroup ) Deprecated

func HerOk

func HerOk() (HttpErrReturn, StatusCode)

data将会自动转化为json

func HerOkWithData

func HerOkWithData(data interface{}) (HttpErrReturn, StatusCode)

data将会自动转化为json

func HerOkWithDataAndUsedTime

func HerOkWithDataAndUsedTime(data interface{}, time time.Duration) (HttpErrReturn, StatusCode)

携带花费时间 Data块会分为 raw 与 usedTime 标记;raw 装载原始数据,usedTime 装载运行所用时间,单位为秒

func HerOkWithString

func HerOkWithString(str string) (HttpErrReturn, StatusCode)

string

func HerRaw

func HerRaw()

func HttpRecoverBasic

func HttpRecoverBasic(w *http.ResponseWriter, re interface{})

func HttpReturn

func HttpReturn(w *http.ResponseWriter, desc, errCode, data string, MakeHERxxx MakeHERxxx)

func HttpReturnArgInvalid

func HttpReturnArgInvalid(w *http.ResponseWriter, argName string)

func HttpReturnHER

func HttpReturnHER(w *http.ResponseWriter, her *HttpErrReturn, statusCode StatusCode, url string)

func HttpReturnOk

func HttpReturnOk(w *http.ResponseWriter)

func HttpReturnOkWithData

func HttpReturnOkWithData(w *http.ResponseWriter, data string)

func PostByProxy

func PostByProxy(webUrl string, body interface{}, v interface{}, proxyUrl string) (e error)

func PostJ

func PostJ(u string, body interface{}, v interface{}) (e error)

http post request with json

func RegisterActions

func RegisterActions() error

启用所有路由

func TrafficGuard

func TrafficGuard() middleware.MiddewareFunc

Types

type ActionFunc

type ActionFunc func(ActionPackage) (HttpErrReturn, StatusCode)

type ActionFuncWS

type ActionFuncWS func(ActionPackage, ActionPackageWS) error

type ActionGroup

type ActionGroup struct {
	Path      string
	Deprecate bool
	NewPath   string
	Freq      float64
}

func (ActionGroup) Deprecated

func (a ActionGroup) Deprecated(substitute string) ActionGroup

用于弃用某个API并提示使用新API

func (ActionGroup) GET

func (a ActionGroup) GET(path string, handler ActionFunc)

添加一个Get请求

func (ActionGroup) GET_CONTENT

func (a ActionGroup) GET_CONTENT(path string, handler ActionFunc)

用于返回content内容

func (ActionGroup) GET_DO

func (a ActionGroup) GET_DO(path string, handler ActionFunc)

只返回data,不返回其他的任何信息 DO: DATA ONLY

func (ActionGroup) IsDeprecated

func (a ActionGroup) IsDeprecated(path string) bool

func (ActionGroup) POST

func (a ActionGroup) POST(path string, handler ActionFunc)

添加一个Post请求

func (ActionGroup) POST_CONTENT

func (a ActionGroup) POST_CONTENT(path string, handler ActionFunc)

用于返回content内容

func (ActionGroup) SetFreq

func (a ActionGroup) SetFreq(freqPerSec float64) ActionGroup

func (ActionGroup) WS

func (a ActionGroup) WS(path string, handler ActionFuncWS)

添加一个websocket请求 cc规范:必须在请求路径末端添加ws字段来提示这一请求为websocket请求 例:/imai_mami/no/koto/ga/suki/ws

type ActionGroupFunc

type ActionGroupFunc func(ActionGroup) error

type ActionPackage

type ActionPackage struct {
	R *http.Request
	W *http.ResponseWriter
}

func (ActionPackage) GetBodyUnmarshal

func (R ActionPackage) GetBodyUnmarshal(v interface{}) error

func (*ActionPackage) GetCookie

func (pap *ActionPackage) GetCookie(key string) (string, error)

func (ActionPackage) GetFormValue

func (R ActionPackage) GetFormValue(key string) string

func (*ActionPackage) SetCookie

func (pap *ActionPackage) SetCookie(cookie *http.Cookie)

type ActionPackageWS

type ActionPackageWS struct {
	C *websocket.Conn
}

func (*ActionPackageWS) ReadBinary

func (pR *ActionPackageWS) ReadBinary() ([]byte, error)

func (*ActionPackageWS) ReadJson

func (pR *ActionPackageWS) ReadJson(v interface{}) (e error)

将ws读取数据转化为json error总是断连错误

func (*ActionPackageWS) ReadString

func (pR *ActionPackageWS) ReadString() (string, error)

将ws的读取数据转化为字符串

func (*ActionPackageWS) WriteBinary

func (pR *ActionPackageWS) WriteBinary(b []byte) (e error)

func (*ActionPackageWS) WriteJson

func (pR *ActionPackageWS) WriteJson(data interface{}) (e error)

func (*ActionPackageWS) WriteString

func (pR *ActionPackageWS) WriteString(str string) (e error)

type H

type H map[string]interface{}

type HttpErrReturn

type HttpErrReturn struct {
	ErrCod string // 内部错误代码,与http状态码不同见第四行
	Desc   string // 错误描述
	Data   string // 携带数据
}

用于返回http状态信息,格式为json

func MakeHER

func MakeHER(desc, errcode string) *HttpErrReturn

创建一个错误返回

func MakeHER200

func MakeHER200(desc, errcode string) (*HttpErrReturn, int)

server Ok 请求返回成功

func MakeHER400

func MakeHER400(desc, errcode string) (*HttpErrReturn, int)

server Bad Request 请求非法,请检查错误信息后重试

func MakeHER401

func MakeHER401(desc, errcode string) (*HttpErrReturn, int)

server Unauthorized 未授权

func MakeHER404

func MakeHER404(desc, errcode string) (*HttpErrReturn, int)

server Not Found 没有这个资源

func MakeHER500

func MakeHER500(desc, errcode string) (*HttpErrReturn, int)

server Server Error 服务器内部错误

type MakeHERxxx

type MakeHERxxx func(desc, errcode string) (*HttpErrReturn, int)

用于返回http状态信息,格式为json

type StatusCode

type StatusCode int

用于返回http状态信息,格式为json

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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