Skip to content

Commit 0f24cac

Browse files
author
alpha
committed
fix gin router and post create
1 parent f03afc4 commit 0f24cac

3 files changed

Lines changed: 5 additions & 4 deletions

File tree

create/template/controller_echo.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func post{{.Name}}(c echo.Context) error {
3737
if err := c.Bind({{.ShortName}}); err != nil {
3838
return c.JSON(200, NewRespBad("参数失败:"+err.Error()))
3939
}
40-
if err := {{.ShortName}}.update(); err != nil {
40+
if err := {{.ShortName}}.create(); err != nil {
4141
return c.JSON(200, NewRespFault("创建{{.LowName}}失败:"+err.Error()))
4242
}
4343
return c.JSON(200, NewRespOK("创建{{.LowName}}成功"))

create/template/controller_gin.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func post{{.Name}}(c *gin.Context) {
3939
c.JSON(200, NewRespBad("参数失败:"+err.Error()))
4040
return
4141
}
42-
if err := {{.ShortName}}.update(); err != nil {
42+
if err := {{.ShortName}}.create(); err != nil {
4343
c.JSON(200, NewRespFault("创建{{.LowName}}失败:"+err.Error()))
4444
return
4545
}

create/template/gin.tmpl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ var ops []option
1818

1919
func initRouter() {
2020
r := gin.Default()
21-
r.Run(conf.Port)
21+
for _,v:=range ops{
22+
v(r)
23+
}
2224
srv := &http.Server{
2325
Addr: conf.Port,
2426
Handler: r,
2527
}
26-
2728
go func() {
2829
if err := srv.ListenAndServe(); err != nil && errors.Is(err, http.ErrServerClosed) {
2930
logger.Printf("listen: %s\n", err)

0 commit comments

Comments
 (0)