Skip to content

Commit

Permalink
fix(api): response data.code => http.status (#17)
Browse files Browse the repository at this point in the history
* fix:response data.code => http status
  • Loading branch information
chanoe authored Dec 22, 2021
1 parent b806e67 commit 1058f6c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ google
golint

./auth.yaml
exam

8 changes: 4 additions & 4 deletions apiserver/response/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ type responseData struct {
func SrvErrWithRest(resp *restful.Response, srvErr *errcode2.SrvError, data interface{}) {
status := errcode2.CodeToStatus(srvErr.Code())
resp.WriteHeaderAndEntity(status, responseData{
Code: srvErr.Code(),
Code: status,
Msg: srvErr.Msg(),
Data: data,
})
}

func DefineWithRest(resp *restful.Response, status, code int, msg string, data interface{}) {
resp.WriteHeaderAndEntity(status, responseData{
Code: code,
Code: status,
Msg: msg,
Data: data,
})
Expand All @@ -49,7 +49,7 @@ func SrvErrWithWriter(w http.ResponseWriter, serErr *errcode2.SrvError, data int
status := errcode2.CodeToStatus(serErr.Code())
w.WriteHeader(status)
resp := responseData{
Code: serErr.Code(),
Code: status,
Msg: serErr.Msg(),
Data: data,
}
Expand All @@ -61,7 +61,7 @@ func SrvErrWithWriter(w http.ResponseWriter, serErr *errcode2.SrvError, data int
func DefineWithWriter(w http.ResponseWriter, status, code int, msg string, data interface{}) {
w.WriteHeader(status)
resp := responseData{
Code: code,
Code: status,
Msg: msg,
Data: data,
}
Expand Down
2 changes: 1 addition & 1 deletion errcode/err_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import "net/http"
// the HTTP status code 0~700 is compatible.
const (
// CodeSuccess.
CodeSuccess = 0
CodeSuccess = 200
// CodeUnexpectedError.
CodeUnexpectedError = iota + 10000
CodeInvalidAccessToken
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
github.com/go-sql-driver/mysql v1.6.0
github.com/go-stack/stack v1.8.1 // indirect
github.com/golang-jwt/jwt v3.2.1+incompatible
github.com/google/gnostic v0.5.7 // indirect
github.com/google/uuid v1.3.0
github.com/json-iterator/go v1.1.12 // indirect
github.com/lib/pq v1.10.2 // indirect
Expand All @@ -36,6 +37,7 @@ require (
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
golang.org/x/net v0.0.0-20211109214657-ef0fda0de508 // indirect
golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602
google.golang.org/protobuf v1.27.1 // indirect
gorm.io/driver/mysql v1.1.3
gorm.io/gorm v1.22.2
)
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,8 @@ github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Z
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/cel-go v0.7.3/go.mod h1:4EtyFAHT5xNr0Msu0MJjyGxPUgdr9DlcaPyzLt/kkt8=
github.com/google/cel-spec v0.5.0/go.mod h1:Nwjgxy5CbjlPrtCWjeDjUyKMl8w41YBYGjsyDdqk0xA=
github.com/google/gnostic v0.5.7 h1:0x05jSyQvEQj2s7X6zg9Mdk1Gf9vI2DzSBJbMIVdiMU=
github.com/google/gnostic v0.5.7/go.mod h1:73MKFl6jIHelAJNaBGFzt3SPtZULs9dYrGFt8OiIsHQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
Expand Down Expand Up @@ -1715,6 +1717,7 @@ google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6D
google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20201019141844-1ed22bb0c154/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20201102152239-715cce707fb0/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
Expand Down Expand Up @@ -1769,6 +1772,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down

0 comments on commit 1058f6c

Please sign in to comment.