optimize api new (#216)

master v1.0.28
kingxt 4 years ago committed by GitHub
parent 24fb29a356
commit e0afe0b4bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,6 +3,7 @@ package new
import ( import (
"os" "os"
"path/filepath" "path/filepath"
"strings"
"text/template" "text/template"
"github.com/tal-tech/go-zero/tools/goctl/api/gogen" "github.com/tal-tech/go-zero/tools/goctl/api/gogen"
@ -20,8 +21,8 @@ type Response {
} }
service {{.name}}-api { service {{.name}}-api {
@handler GreetHandler @handler {{.handler}}Handler
get /greet/from/:name(Request) returns (Response); get /from/:name(Request) returns (Response);
} }
` `
@ -53,7 +54,8 @@ func NewService(c *cli.Context) error {
defer fp.Close() defer fp.Close()
t := template.Must(template.New("template").Parse(apiTemplate)) t := template.Must(template.New("template").Parse(apiTemplate))
if err := t.Execute(fp, map[string]string{ if err := t.Execute(fp, map[string]string{
"name": dirName, "name": dirName,
"handler": strings.Title(dirName),
}); err != nil { }); err != nil {
return err return err
} }

Loading…
Cancel
Save