新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)GoFrame教程:GoFrame 錯誤碼特性-錯誤碼接口
基本介紹
框架提供了默認(rèn)的錯誤碼組件?gcode?,錯誤碼使用接口化設(shè)計,以實(shí)現(xiàn)高擴(kuò)展性。

為信豐等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及信豐網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為網(wǎng)站建設(shè)、成都網(wǎng)站制作、信豐網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!
接口定義
// Code is universal error code interface definition.
type Code interface {
// Code returns the integer number of current error code.
Code() int
// Message returns the brief message for current error code.
Message() string
// Detail returns the detailed information of current error code,
// which is mainly designed as an extension field for error code.
Detail() interface{}
}默認(rèn)實(shí)現(xiàn)
框架提供了默認(rèn)實(shí)現(xiàn)?gcode.Code?的結(jié)構(gòu)體,開發(fā)者可以直接通過?New/WithCode?方法創(chuàng)建錯誤碼:
- 格式:
// New creates and returns an error code.
// Note that it returns an interface object of Code.
func New(code int, message string, detail interface{}) Code- 示例:
func ExampleNew() {
c := gcode.New(1, "custom error", "detailed description")
fmt.Println(c.Code())
fmt.Println(c.Message())
fmt.Println(c.Detail())
// Output:
// 1
// custom error
// detailed description
}如果開發(fā)者覺得框架默認(rèn)實(shí)現(xiàn)?gcode.Code?的結(jié)構(gòu)體不滿足需求,可以自行定義,只需實(shí)現(xiàn)?gcode.Code?即可。
本文題目:創(chuàng)新互聯(lián)GoFrame教程:GoFrame 錯誤碼特性-錯誤碼接口
地址分享:http://m.fisionsoft.com.cn/article/cocpddj.html


咨詢
建站咨詢
