gitee.com/hongliu9527/go-tools@v0.0.8/errors/gerror/gerror_error_code.go (about) 1 /* 2 * @Author: hongliu 3 * @Date: 2022-12-29 10:51:12 4 * @LastEditors: hongliu 5 * @LastEditTime: 2022-12-29 11:28:50 6 * @FilePath: \go-tools\errors\gerror\gerror_error_code.go 7 * @Description:带编码的错误处理 8 * 9 * Copyright (c) 2022 by 洪流, All Rights Reserved. 10 */ 11 12 package gerror 13 14 import ( 15 "gitee.com/hongliu9527/go-tools/errors/gcode" 16 ) 17 18 // Code returns the error code. 19 // It returns CodeNil if it has no error code. 20 func (err *Error) Code() gcode.Code { 21 if err == nil { 22 return gcode.CodeNil 23 } 24 if err.code == gcode.CodeNil { 25 return Code(err.Unwrap()) 26 } 27 return err.code 28 } 29 30 // SetCode updates the internal code with given code. 31 func (err *Error) SetCode(code gcode.Code) { 32 if err == nil { 33 return 34 } 35 err.code = code 36 }