|
|
|
@ -79,7 +79,8 @@ func (u *Kit) Generate(plugin *protogen.Plugin) error { |
|
|
|
|
u.genPost(serverName, t, m) |
|
|
|
|
case protogen2.METHOD_DELETE: |
|
|
|
|
u.genDelete(serverName, t, m) |
|
|
|
|
|
|
|
|
|
case protogen2.METHOD_PUT: |
|
|
|
|
u.genPut(serverName, t, m) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -162,3 +163,29 @@ func (u *Kit) genDelete(serverName string, t *protogen.GeneratedFile, m *protoge |
|
|
|
|
}`) |
|
|
|
|
t.P("}") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (u *Kit) genPut(serverName string, t *protogen.GeneratedFile, m *protogen.Method) { |
|
|
|
|
t.P("func http", m.GoName, "Handler(srv ", serverName, "Server,m ...middleware.Middleware)func(c *gin.Context){") |
|
|
|
|
t.P(`return func(c *gin.Context) { |
|
|
|
|
var post `, m.Input.GoIdent.GoName, ` |
|
|
|
|
resp := response.New(c) |
|
|
|
|
if err := resp.BindJSON(&post); err != nil { |
|
|
|
|
resp.Error(err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
h := func(ctx context.Context, a any) (any, error) { |
|
|
|
|
return srv.`, m.GoName, `(ctx, a.(*`, m.Input.GoIdent.GoName, `)) |
|
|
|
|
} |
|
|
|
|
out, err := middleware.HttpMiddleware(c, h, m...)(c, &post) |
|
|
|
|
if err != nil { |
|
|
|
|
resp.Error(err) |
|
|
|
|
} else { |
|
|
|
|
if v, ok := out.(*`, m.Output.GoIdent.GoName, `); ok { |
|
|
|
|
resp.Success(v) |
|
|
|
|
} else { |
|
|
|
|
resp.Error(errors.InternalServer("RESULT_TYPE_ERROR", "`, m.Output.GoIdent.GoName, `")) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}`) |
|
|
|
|
t.P("}") |
|
|
|
|
} |
|
|
|
|