File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ test :
2+ go test -v ./...
Original file line number Diff line number Diff line change @@ -2,9 +2,9 @@ package main
22
33import (
44 "errors"
5- "github.com/muxi-Infra/muxi-micro/pkg/1"
6- "github.com/muxi-Infra/muxi-micro/pkg/1/zapx"
75 "github.com/muxi-Infra/muxi-micro/pkg/errs"
6+ "github.com/muxi-Infra/muxi-micro/pkg/logger"
7+ "github.com/muxi-Infra/muxi-micro/pkg/logger/zapx"
88)
99
1010var DBNOData = errs .NewErr ("db_no_data" , "db has no data" )
@@ -26,13 +26,13 @@ func SearchUser(id int) error {
2626}
2727
2828func main () {
29- l := zapx .NewDefaultZapLogger ("./logs" , logger . EnvTest )
29+ l := zapx .NewDefaultZapLogger ()
3030 id := 1
3131 A (id , l )
32- l .Info ("查询出错id:" , logger .Int ( "id" , id ) )
32+ l .Info ("查询出错id:" , logger.Field { "id" : id } )
3333}
3434
3535func A (id int , l logger.Logger ) {
3636 err := SearchUser (id )
37- l .Error ("查询数据库出错:" , logger .Error (err ))
37+ l .Error ("查询数据库出错:" + err .Error ())
3838}
Original file line number Diff line number Diff line change @@ -23,32 +23,35 @@ func main() {
2323 engine .WithEnv (static .EnvDev ),
2424 )
2525
26- // 1. 注册不需要请求体和用户认证的路由
27- router .GET ("/ping" , handler .Wrap (func (ctx * gin.Context ) t_http.Response {
28- return t_http.Response {
26+ // 1. 注册不需要请求体
27+ router .GET ("/ping" , handler .Wrap (func (ctx * gin.Context ) {
28+
29+ handler .HandleResponse (ctx , t_http.Response {
2930 HttpCode : http .StatusOK ,
3031 Code : 0 ,
3132 Message : "pong" ,
3233 Data : nil ,
33- }
34+ })
3435 }))
3536
36- // 2. 注册需要请求体但不需要用户认证的路由
37- router .POST ("/login" , handler .WrapReq (func (ctx * gin.Context , req LoginRequest ) t_http. Response {
37+ // 2. 注册需要请求体
38+ router .POST ("/login" , handler .WrapReq (func (ctx * gin.Context , req LoginRequest ) {
3839 // 模拟登录逻辑
3940 if req .Username == "admin" && req .Password == "123456" {
40- return t_http.Response {
41+ handler . HandleResponse ( ctx , t_http.Response {
4142 HttpCode : http .StatusOK ,
4243 Message : "登录成功" ,
4344 Data : "token-string" ,
44- }
45+ })
46+ return
4547 }
46- return t_http.Response {
48+ handler . HandleResponse ( ctx , t_http.Response {
4749 HttpCode : http .StatusUnauthorized ,
4850 Code : 40100 ,
4951 Message : "用户名或密码错误" ,
5052 Data : nil ,
51- }
53+ })
54+ return
5255 }))
5356
5457 router .Run ("0.0.0.0:8080" )
You can’t perform that action at this time.
0 commit comments