日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)GoFrame教程:GoFrame錯(cuò)誤碼特性-錯(cuò)誤碼實(shí)現(xiàn)

當(dāng)業(yè)務(wù)需要更復(fù)雜的錯(cuò)誤碼定義時(shí),我們可以自定義實(shí)現(xiàn)業(yè)務(wù)自己的錯(cuò)誤碼,只需要實(shí)現(xiàn)?gcode.Code?相關(guān)的接口即可。

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡(jiǎn)單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長期合作伙伴,公司提供的服務(wù)項(xiàng)目有:空間域名、網(wǎng)頁空間、營銷軟件、網(wǎng)站建設(shè)、牟平網(wǎng)站維護(hù)、網(wǎng)站推廣。

我們來看個(gè)例子。

自定義錯(cuò)誤碼

定義結(jié)構(gòu)體并實(shí)現(xiàn)?gcode.code?接口定義的方法

type BizCode struct {
	code    int
	message string
	detail  BizCodeDetail
}
type BizCodeDetail struct {
	Code     string
	HttpCode int
}

func (c BizCode) BizDetail() BizCodeDetail {
	return c.detail
}

func (c BizCode) Code() int {
	return c.code
}

func (c BizCode) Message() string {
	return c.message
}

func (c BizCode) Detail() interface{} {
	return c.detail
}

func New(httpCode int, code string, message string) gcode.Code {
	return BizCode{
		code:    0,
		message: message,
		detail: BizCodeDetail{
			Code:     code,
			HttpCode: httpCode,
		},
	}
}

定義業(yè)務(wù)錯(cuò)誤碼

var (
	CodeNil      = New(200, "OK", "")
	CodeNotFound = New(404, "Not Found", "Resource does not exist")
	CodeInternal = New(500, "Internal Error", "An error occurred internally")
	// ...
)

使用到中間件

func ResponseHandler(r *ghttp.Request) {
	r.Middleware.Next()
	// There's custom buffer content, it then exits current handler.
	if r.Response.BufferLength() > 0 {
		return
	}
	res, err := r.GetHandlerResponse()
	code := gerror.Code(err)
	if code == gcode.CodeNil && err != nil {
		code = CodeInternal
	} else {
		code = CodeNil
	}
	if bizCode, ok := code.(BizCode); ok {
		r.Response.WriteStatus(bizCode.BizDetail().HttpCode)
	}
	_ = r.Response.WriteJson(g.Map{
		`code`:    gcode.CodeOK.Code(),
		`message`: gcode.CodeOK.Message(),
		`data`:    res,
	})
}

分享題目:創(chuàng)新互聯(lián)GoFrame教程:GoFrame錯(cuò)誤碼特性-錯(cuò)誤碼實(shí)現(xiàn)
分享鏈接:http://m.5511xx.com/article/coshsos.html