Skip to content

Commit 404a548

Browse files
committed
feat: 简化error code
1 parent e211517 commit 404a548

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

pkg/ecode/ecode.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ecode
22

33
import (
44
"gin_example_with_generic/pkg/errors"
5+
"net/http"
56
)
67

78
type ErrCode struct {
@@ -10,19 +11,19 @@ type ErrCode struct {
1011
Message string
1112
}
1213

13-
func (coder ErrCode) Code() int {
14-
return coder.ErrCode
14+
func (e *ErrCode) Code() int {
15+
return e.ErrCode
1516
}
1617

17-
func (coder ErrCode) String() string {
18-
return coder.Message
18+
func (e *ErrCode) String() string {
19+
return e.Message
1920
}
2021

21-
func (coder ErrCode) HTTPStatus() int {
22-
if coder.HttpStatus == 0 {
23-
return 500
22+
func (e *ErrCode) HTTPStatus() int {
23+
if e.HttpStatus == 0 {
24+
return http.StatusInternalServerError
2425
}
25-
return coder.HttpStatus
26+
return e.HttpStatus
2627
}
2728

2829
func register(code int, httpStatus int, message string) {

0 commit comments

Comments
 (0)