add bookstore example
This commit is contained in:
28
example/bookstore/api/internal/handler/addhandler.go
Normal file
28
example/bookstore/api/internal/handler/addhandler.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"bookstore/api/internal/logic"
|
||||
"bookstore/api/internal/svc"
|
||||
"bookstore/api/internal/types"
|
||||
"net/http"
|
||||
|
||||
"github.com/tal-tech/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func addHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.AddReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.Error(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := logic.NewAddLogic(r.Context(), ctx)
|
||||
resp, err := l.Add(req)
|
||||
if err != nil {
|
||||
httpx.Error(w, err)
|
||||
} else {
|
||||
httpx.WriteJson(w, http.StatusOK, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
28
example/bookstore/api/internal/handler/checkhandler.go
Normal file
28
example/bookstore/api/internal/handler/checkhandler.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"bookstore/api/internal/logic"
|
||||
"bookstore/api/internal/svc"
|
||||
"bookstore/api/internal/types"
|
||||
"net/http"
|
||||
|
||||
"github.com/tal-tech/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func checkHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CheckReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.Error(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := logic.NewCheckLogic(r.Context(), ctx)
|
||||
resp, err := l.Check(req)
|
||||
if err != nil {
|
||||
httpx.Error(w, err)
|
||||
} else {
|
||||
httpx.WriteJson(w, http.StatusOK, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
24
example/bookstore/api/internal/handler/routes.go
Normal file
24
example/bookstore/api/internal/handler/routes.go
Normal file
@@ -0,0 +1,24 @@
|
||||
// DO NOT EDIT, generated by goctl
|
||||
package handler
|
||||
|
||||
import (
|
||||
"bookstore/api/internal/svc"
|
||||
"net/http"
|
||||
|
||||
"github.com/tal-tech/go-zero/rest"
|
||||
)
|
||||
|
||||
func RegisterHandlers(engine *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
engine.AddRoutes([]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/add",
|
||||
Handler: addHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/check",
|
||||
Handler: checkHandler(serverCtx),
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user