Files
go-zero/example/bookstore/api/internal/handler/addhandler.go

30 lines
575 B
Go
Raw Normal View History

2020-09-03 23:26:04 +08:00
package handler
import (
2020-09-27 11:10:21 +08:00
"net/http"
2020-09-03 23:26:04 +08:00
"bookstore/api/internal/logic"
"bookstore/api/internal/svc"
"bookstore/api/internal/types"
"github.com/tal-tech/go-zero/rest/httpx"
)
func AddHandler(ctx *svc.ServiceContext) http.HandlerFunc {
2020-09-03 23:26:04 +08:00
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)
}
}
}