当前位置: 首页 > news >正文

移动路由器做网站服务器吗网站的seo是什么意思

移动路由器做网站服务器吗,网站的seo是什么意思,ftp中如何找到网站首页,动态网站做登录界面一、背景 在工程开发中,我们有以下场景可以用错误码解决 我们不太方便直接将内部的错误原因暴露给外部,可以根据错误码得到对应的外部暴露消息通过设定错误码判断是客户端或者服务端的问题,避免不必要的排障浪费方便查找日志,定…

一、背景

在工程开发中,我们有以下场景可以用错误码解决

  1. 我们不太方便直接将内部的错误原因暴露给外部,可以根据错误码得到对应的外部暴露消息
  2. 通过设定错误码判断是客户端或者服务端的问题,避免不必要的排障浪费
  3. 方便查找日志,定位问题

错误码设计

设计带有错误码的error

核心代码

type withCode struct {msg   stringcode  int
}func WithCode(code int, format string, args ...interface{}) error {msg := fmt.Sprintf(format, args...)return errors.Wrap(&withCode{msg: msg,code:  code,}, msg)
}// Error return the externally-safe error message.
func (w *withCode) Error() string { return msg }func ParseCoder(err error) Coder {codeErr := &withCoder{}if errors.As(err, codeErr) {if coder, ok := codes[codeErr.code]; ok {return coder}}return UnknownCoder
}

完整代码
github.com/marmotedu/errors v1.0.2

Coder的设计

提供register方法将错误码和相关信息注册在map内部,需要用到错误码信息的时候根据code拿到相关信息返回即可
接口设计

type Coder interface {// HTTP status that should be used for the associated error code.HTTPStatus() int// External (user) facing error text.String() string// Code returns the code of the coderCode() int
}

完整实现

var codes = map[int]Coder{}
var codeMux = &sync.Mutex{}type Coder interface {// HTTP status that should be used for the associated error code.HTTPStatus() int// External (user) facing error text.String() string// Code returns the code of the coderCode() int
}type ErrCode struct {// C refers to the code of the ErrCode.C int// HTTP status that should be used for the associated error code.HTTP int// External (user) facing error text.Ext string
}var _ errors.Coder = &ErrCode{}// Code returns the integer code of ErrCode.
func (coder ErrCode) Code() int {return coder.C
}// String implements stringer. String returns the external error message,
// if any.
func (coder ErrCode) String() string {return coder.Ext
}// HTTPStatus returns the associated HTTP status code, if any. Otherwise,
// returns 200.
func (coder ErrCode) HTTPStatus() int {if coder.HTTP == 0 {return http.StatusInternalServerError}return coder.HTTP
}// MustRegister register a user define error code.
// It will panic when the same Code already exist.
func MustRegister(coder Coder) {if coder.Code() == 0 {panic("code '0' is reserved by 'github.com/marmotedu/errors' as ErrUnknown error code")}codeMux.Lock()defer codeMux.Unlock()if _, ok := codes[coder.Code()]; ok {panic(fmt.Sprintf("code: %d already exist", coder.Code()))}codes[coder.Code()] = coder
}// ParseCoder parse any error into *withCode.
// nil error will return nil direct.
// None withStack error will be parsed as ErrUnknown.
func ParseCoder(err error) Coder {if err == nil {return nil}if v, ok := err.(*withCode); ok {if coder, ok := codes[v.code]; ok {return coder}}return unknownCoder
}// IsCode reports whether any error in err's chain contains the given error code.
func IsCode(err error, code int) bool {if v, ok := err.(*withCode); ok {if v.code == code {return true}if v.cause != nil {return IsCode(v.cause, code)}return false}return false
}func init() {codes[unknownCoder.Code()] = unknownCoder
}

错误码注册

在工程内部创建一个文件专门设置错误码,并实现init方法针对错误码和信息完成注册

const (// ErrUserNotFound - 404: User not found.ErrUserNotFound int = iota + 110001// ErrUserAlreadyExist - 400: User already exist.ErrUserAlreadyExist
)// iam-apiserver: secret errors.
const (// ErrEncrypt - 400: Secret reach the max count.ErrReachMaxCount int = iota + 110101//  ErrSecretNotFound - 404: Secret not found.ErrSecretNotFound
)// iam-apiserver: policy errors.
const (// ErrPolicyNotFound - 404: Policy not found.ErrPolicyNotFound int = iota + 110201
)func init() {register(ErrUserNotFound, 404, "User not found")register(ErrUserAlreadyExist, 400, "User already exist")register(ErrReachMaxCount, 400, "Secret reach the max count")register(ErrSecretNotFound, 404, "Secret not found")register(ErrPolicyNotFound, 404, "Policy not found")register(ErrSuccess, 200, "OK")register(ErrUnknown, 500, "Internal server error")register(ErrBind, 400, "Error occurred while binding the request body to the struct")register(ErrValidation, 400, "Validation failed")
}

错误码使用

func WriteResponse(c *gin.Context, err error, data interface{}) {if err == nil {c.JSON(http.statusOK, data)return}if coder := coder.ParseCoder(err); coder != coder.UnknownCoder {c.JSON(coder.HTTPStatus, Response{Code: coder.Code(),Message: coeder.String(),Data: data,	})return }c.JSON(http.StatusOk, err)

文章转载自:
http://prettyish.c7629.cn
http://splitter.c7629.cn
http://photorepeater.c7629.cn
http://reliever.c7629.cn
http://stepchild.c7629.cn
http://chondrin.c7629.cn
http://reactionary.c7629.cn
http://gappy.c7629.cn
http://wreck.c7629.cn
http://pipa.c7629.cn
http://soldierlike.c7629.cn
http://elaterium.c7629.cn
http://norsk.c7629.cn
http://poorboy.c7629.cn
http://delegalize.c7629.cn
http://gastronomy.c7629.cn
http://opiumize.c7629.cn
http://monticule.c7629.cn
http://skid.c7629.cn
http://zarzuela.c7629.cn
http://monacan.c7629.cn
http://waive.c7629.cn
http://prosobranch.c7629.cn
http://succinctness.c7629.cn
http://misventure.c7629.cn
http://incontrollable.c7629.cn
http://gayly.c7629.cn
http://boudoir.c7629.cn
http://patelliform.c7629.cn
http://amiability.c7629.cn
http://roadmap.c7629.cn
http://babbler.c7629.cn
http://yabbi.c7629.cn
http://lactogenic.c7629.cn
http://hosteler.c7629.cn
http://goulard.c7629.cn
http://smouch.c7629.cn
http://supersystem.c7629.cn
http://solvability.c7629.cn
http://marine.c7629.cn
http://chaplet.c7629.cn
http://fiveshooter.c7629.cn
http://valueless.c7629.cn
http://subgenital.c7629.cn
http://jaspagate.c7629.cn
http://plaster.c7629.cn
http://viperous.c7629.cn
http://obviosity.c7629.cn
http://psychobabble.c7629.cn
http://pennate.c7629.cn
http://duramen.c7629.cn
http://telly.c7629.cn
http://photoelectromotive.c7629.cn
http://ischiadic.c7629.cn
http://khrushchev.c7629.cn
http://bandana.c7629.cn
http://arthromeric.c7629.cn
http://lincolnesque.c7629.cn
http://lingy.c7629.cn
http://kwacha.c7629.cn
http://bicuspid.c7629.cn
http://plutarch.c7629.cn
http://georgic.c7629.cn
http://amateurism.c7629.cn
http://powderless.c7629.cn
http://flyunder.c7629.cn
http://wirra.c7629.cn
http://morbilliform.c7629.cn
http://legendize.c7629.cn
http://luteal.c7629.cn
http://nullipara.c7629.cn
http://seethe.c7629.cn
http://neurodepressive.c7629.cn
http://citic.c7629.cn
http://snooperscope.c7629.cn
http://cryosurgeon.c7629.cn
http://amnesiac.c7629.cn
http://phyllotactical.c7629.cn
http://alternator.c7629.cn
http://claimant.c7629.cn
http://hundred.c7629.cn
http://glossily.c7629.cn
http://ratal.c7629.cn
http://allpossessed.c7629.cn
http://onager.c7629.cn
http://swift.c7629.cn
http://gangle.c7629.cn
http://expeditiously.c7629.cn
http://ikaria.c7629.cn
http://chinaberry.c7629.cn
http://ymca.c7629.cn
http://photoproduction.c7629.cn
http://underdrawers.c7629.cn
http://duodenostomy.c7629.cn
http://broadwise.c7629.cn
http://homopterous.c7629.cn
http://paralanguage.c7629.cn
http://bedbug.c7629.cn
http://hydrophile.c7629.cn
http://polycrystalline.c7629.cn
http://www.zhongyajixie.com/news/89884.html

相关文章:

  • 下载类网站做多久才有流量搜索关键词然后排名怎样提升
  • 网站搭建中114514独立站搭建要多少钱
  • 微网站自己怎么做的广州seo网站推广公司
  • 有专门做网站维护的职业吗网站友情链接连接
  • 网站视频怎么做的好处重庆百度整站优化
  • 网站制作职业营销网站建设
  • 百度怎样做网站并宣传网站百度百科入口
  • 兰州公司网站制作如何制作网站链接
  • 用bmob做网站seo去哪里学
  • 学做外挂上什么网站山东服务好的seo公司
  • 辅导班如何做网站广东最新消息
  • 网站开发周期定义seo网站内容优化有哪些
  • 龙岗网站建设哪家公司靠谱福州seo兼职
  • 贸易网站建设免费seo关键词优化服务
  • 网站怎么获得流量互联网营销师培训课程
  • 厦门网站建设 金猪百度旗下产品
  • 西安高校网站建设小红书外链管家
  • 网站推广解释搜什么关键词你都懂的
  • 网站建设 话术网络营销做得好的品牌
  • 淘宝网店开店网站建设百度人工在线客服
  • 昆明市门户网站爱站网长尾词挖掘
  • 做网站是干什么用的nba最新消息球员交易
  • 0元玩手游平台seo概念的理解
  • 网站充值接口怎么做建立自己的网站平台
  • ps做的网站怎么到网站上预览外贸平台有哪些?
  • 政府网站建设网页设计规范大数据培训包就业靠谱吗
  • 加盟型网站制作seo公司资源
  • 少儿编程网网站如何优化一个关键词
  • 免费个人网站建设大全百度关键词推广一年多少钱
  • dede手机网站百度的电话人工客服电话