完善代码

This commit is contained in:
zchh 2021-01-18 19:56:07 +08:00
parent d47a95df8d
commit 17d6795921
3 changed files with 10 additions and 5 deletions

View File

@ -1,11 +1,14 @@
package codes
// A Code is an unsigned 32-bit error code as defined in the beego spec.
type Code uint32
const (
// SessionSessionStartError means func SessionStart error in session module.
SessionSessionStartError Code = 5001001
)
// CodeToStr is a map about Code and Code's message
var CodeToStr = map[Code]string{
SessionSessionStartError : `"SESSION_MODULE_SESSION_START_ERROR"`,
}
}

View File

@ -6,9 +6,10 @@ import (
"strconv"
)
// The `Error`type defines custom error for Beego. It is used by every module
// Error type defines custom error for Beego. It is used by every module
// in Beego. Each `Error` message contains three pieces of data: error code,
// error message. More docs http://beego.me/docs/module/error.md
// error message.
// More docs http://beego.me/docs/module/error.md.
type Error struct {
Code codes.Code
Msg string
@ -35,7 +36,7 @@ func (e *Error) Error() string {
return fmt.Sprintf("beego error: code = %s desc = %s", codeSrt, e.GetMessage())
}
// GetCode returns Error's Code
// GetCode returns Error's Code.
func (e *Error) GetCode() codes.Code {
if e != nil {
return e.Code

View File

@ -118,7 +118,7 @@ func TestErrorf(t *testing.T) {
wantErr bool
}{
// TODO: Add test cases.
{name: "1", args: args{codes.SessionSessionStartError, "%s", []interface{}{codes.CodeToStr[codes.SessionSessionStartError]}}},
{name: "1", args: args{codes.SessionSessionStartError, "%s", []interface{}{codes.CodeToStr[codes.SessionSessionStartError]}}, wantErr: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@ -140,6 +140,7 @@ func TestNew(t *testing.T) {
want *Error
}{
// TODO: Add test cases.
{name: "1", args: args{codes.SessionSessionStartError, codes.CodeToStr[codes.SessionSessionStartError]}, want: &Error{Code:codes.SessionSessionStartError, Msg:codes.CodeToStr[codes.SessionSessionStartError]}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {