diff --git a/go.mod b/go.mod index 61842244..851f7f5b 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( ) require ( - github.com/474420502/requests v1.30.0 + github.com/474420502/requests v1.32.1 github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/tidwall/gjson v1.12.0 // indirect diff --git a/go.sum b/go.sum index 908f7693..27c0ccde 100644 --- a/go.sum +++ b/go.sum @@ -32,8 +32,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/474420502/random v0.4.1 h1:HUUyLXRWMijVb7CJoEC16f0aFQOW25Lkr80Mut6PoKU= -github.com/474420502/requests v1.30.0 h1:IVEee0wALTweoXrFsEipQEMakcSQpE5NahyMVUliMNc= -github.com/474420502/requests v1.30.0/go.mod h1:043PKfW//QR069XTYG5WT7t+z+d+8/C5PJtfWzpsf+o= +github.com/474420502/requests v1.32.1 h1:ivr9iMXrYqfdKWS0q15HEFlt1Cjeeu75Hjhbmikg9us= +github.com/474420502/requests v1.32.1/go.mod h1:rrDBE6AfPr0Cclo1lL4Jgw1mIW6TKSCvFgXDuEqlw70= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= diff --git a/goctl_template/api/handler.tpl b/goctl_template/api/handler.tpl index 55383ba9..4810ce25 100644 --- a/goctl_template/api/handler.tpl +++ b/goctl_template/api/handler.tpl @@ -23,6 +23,7 @@ func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc { Message: "unauthorized", }) logx.Info("unauthorized:", err.Error()) + return } // 从Token里获取对应的信息 @@ -34,6 +35,7 @@ func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc { Message: "unauthorized", }) logx.Info("unauthorized:", err.Error()) + return } {{if .HasRequest}}var req types.{{.RequestType}} @@ -58,5 +60,6 @@ func {{.HandlerName}}(svcCtx *svc.ServiceContext) http.HandlerFunc { httpx.ErrorCtx(r.Context(), w, err) logx.Error(err) } + return } } diff --git a/server/home-user-auth/home-user-auth_test.go b/server/home-user-auth/home-user-auth_test.go index 885264f5..d035c13a 100644 --- a/server/home-user-auth/home-user-auth_test.go +++ b/server/home-user-auth/home-user-auth_test.go @@ -1,35 +1,11 @@ package main import ( - "flag" - "fmt" - "fusenapi/server/home-user-auth/internal/config" - "fusenapi/server/home-user-auth/internal/handler" - "fusenapi/server/home-user-auth/internal/svc" "testing" - - "github.com/zeromicro/go-zero/core/conf" - "github.com/zeromicro/go-zero/rest" ) // var configFile = flag.String("f", "etc/home-user-auth.yaml", "the config file") -func GetTestServer() *rest.Server { - flag.Parse() - - var c config.Config - conf.MustLoad(*configFile, &c) - - server := rest.MustNewServer(c.RestConf) - defer server.Stop() - - ctx := svc.NewServiceContext(c) - handler.RegisterHandlers(server, ctx) - - fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port) - return server -} - func TestMain(t *testing.T) { // log.Println(model.RawFieldNames[FsCanteenType]()) main() diff --git a/server/home-user-auth/internal/handler/userbasicinfohandler.go1 b/server/home-user-auth/internal/handler/userbasicinfohandler.go1 deleted file mode 100644 index f943a476..00000000 --- a/server/home-user-auth/internal/handler/userbasicinfohandler.go1 +++ /dev/null @@ -1,37 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/server/home-user-auth/internal/logic" - "fusenapi/server/home-user-auth/internal/svc" - "fusenapi/server/home-user-auth/internal/types" -) - -func UserBasicInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var req types.Request - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - - l := logic.NewUserBasicInfoLogic(r.Context(), svcCtx) - resp := l.UserBasicInfo(&req) - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - } -} diff --git a/server/home-user-auth/internal/handler/userfontshandler.go1 b/server/home-user-auth/internal/handler/userfontshandler.go1 deleted file mode 100644 index ce8effe7..00000000 --- a/server/home-user-auth/internal/handler/userfontshandler.go1 +++ /dev/null @@ -1,37 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/server/home-user-auth/internal/logic" - "fusenapi/server/home-user-auth/internal/svc" - "fusenapi/server/home-user-auth/internal/types" -) - -func UserFontsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var req types.Request - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - - l := logic.NewUserFontsLogic(r.Context(), svcCtx) - resp := l.UserFonts(&req) - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - } -} diff --git a/server/home-user-auth/internal/handler/usergettypehandler.go1 b/server/home-user-auth/internal/handler/usergettypehandler.go1 deleted file mode 100644 index cd759425..00000000 --- a/server/home-user-auth/internal/handler/usergettypehandler.go1 +++ /dev/null @@ -1,37 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/server/home-user-auth/internal/logic" - "fusenapi/server/home-user-auth/internal/svc" - "fusenapi/server/home-user-auth/internal/types" -) - -func UserGetTypeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var req types.Request - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - - l := logic.NewUserGetTypeLogic(r.Context(), svcCtx) - resp := l.UserGetType(&req) - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - } -} diff --git a/server/home-user-auth/internal/handler/usersavebasicinfohandler.go1 b/server/home-user-auth/internal/handler/usersavebasicinfohandler.go1 deleted file mode 100644 index c63ff004..00000000 --- a/server/home-user-auth/internal/handler/usersavebasicinfohandler.go1 +++ /dev/null @@ -1,37 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/server/home-user-auth/internal/logic" - "fusenapi/server/home-user-auth/internal/svc" - "fusenapi/server/home-user-auth/internal/types" -) - -func UserSaveBasicInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var req types.RequestBasicInfoForm - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - - l := logic.NewUserSaveBasicInfoLogic(r.Context(), svcCtx) - resp := l.UserSaveBasicInfo(&req) - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - } -} diff --git a/server/home-user-auth/internal/handler/userstatusconfighandler.go1 b/server/home-user-auth/internal/handler/userstatusconfighandler.go1 deleted file mode 100644 index e29ae441..00000000 --- a/server/home-user-auth/internal/handler/userstatusconfighandler.go1 +++ /dev/null @@ -1,37 +0,0 @@ -package handler - -import ( - "errors" - "net/http" - - "github.com/zeromicro/go-zero/core/logx" - "github.com/zeromicro/go-zero/rest/httpx" - - "fusenapi/server/home-user-auth/internal/logic" - "fusenapi/server/home-user-auth/internal/svc" - "fusenapi/server/home-user-auth/internal/types" -) - -func UserStatusConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var req types.Request - if err := httpx.Parse(r, &req); err != nil { - httpx.OkJsonCtx(r.Context(), w, &types.Response{ - Code: 510, - Message: "parameter error", - }) - logx.Info(err) - return - } - - l := logic.NewUserStatusConfigLogic(r.Context(), svcCtx) - resp := l.UserStatusConfig(&req) - if resp != nil { - httpx.OkJsonCtx(r.Context(), w, resp) - } else { - err := errors.New("server logic is error, resp must not be nil") - httpx.ErrorCtx(r.Context(), w, err) - logx.Error(err) - } - } -} diff --git a/server/home-user-auth/test/useraddresslistlogic_test.go b/server/home-user-auth/test/useraddresslistlogic_test.go new file mode 100644 index 00000000..3ad2cd23 --- /dev/null +++ b/server/home-user-auth/test/useraddresslistlogic_test.go @@ -0,0 +1,60 @@ +package server_test + +import ( + "flag" + "fmt" + "fusenapi/server/home-user-auth/internal/config" + "fusenapi/server/home-user-auth/internal/handler" + "fusenapi/server/home-user-auth/internal/svc" + "log" + "testing" + + "github.com/474420502/requests" + "github.com/zeromicro/go-zero/core/conf" + "github.com/zeromicro/go-zero/rest" +) + +var configFile = flag.String("f", "../etc/home-user-auth.yaml", "the config file") + +func GetTestServer() *rest.Server { + flag.Parse() + + var c config.Config + conf.MustLoad(*configFile, &c) + + server := rest.MustNewServer(c.RestConf) + defer server.Stop() + + ctx := svc.NewServiceContext(c) + handler.RegisterHandlers(server, ctx) + + fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port) + return server +} + +func TestCaseAddressList(t *testing.T) { + server := GetTestServer() + // http.NewRequest("POST", "http://localhost:8888/user/login", body io.Reader) + + ses := requests.NewSession() + tp := ses.Post("http://localhost:8888/user/login") + tp.SetBodyJson(map[string]interface{}{ + "name": "devenv@sina.cn", + "pwd": "$2y$13$6UFDMZQMEfqFYiNLpiUCi.B3fpvGEamPAjIgzUqv/u7jT05nB3pOC", + }) + resp, err := tp.TestInServer(server) + if err != nil { + t.Error(err) + } + result := resp.Json() + token := result.Get("data.token") + ses.Header.Add("Authorization", token.String()) + log.Println(resp.ContentString()) + + resp, err = ses.Get("http://localhost:8888/user/address-list").TestInServer(server) + if err != nil { + panic(err) + } + log.Println(string(resp.Content())) + +}