You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-zero/tools/goctl/api/dartgen/gen.go

52 lines
1.1 KiB
Go

4 years ago
package dartgen
import (
"errors"
"fmt"
4 years ago
"strings"
"github.com/urfave/cli"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/tools/goctl/api/parser"
4 years ago
)
// DartCommand create dart network request code
4 years ago
func DartCommand(c *cli.Context) error {
apiFile := c.String("api")
dir := c.String("dir")
isLegacy := c.Bool("legacy")
hostname := c.String("hostname")
4 years ago
if len(apiFile) == 0 {
return errors.New("missing -api")
}
if len(dir) == 0 {
return errors.New("missing -dir")
}
if len(hostname) == 0 {
fmt.Println("you could use '-hostname' flag to specify your server hostname")
hostname = "go-zero.dev"
}
4 years ago
api, err := parser.Parse(apiFile)
4 years ago
if err != nil {
return err
}
if err := api.Validate(); err != nil {
return err
}
api.Service = api.Service.JoinPrefix()
4 years ago
if !strings.HasSuffix(dir, "/") {
dir = dir + "/"
}
api.Info.Title = strings.Replace(apiFile, ".api", "", -1)
logx.Must(genData(dir+"data/", api, isLegacy))
logx.Must(genApi(dir+"api/", api, isLegacy))
logx.Must(genVars(dir+"vars/", isLegacy, hostname))
if err := formatDir(dir); err != nil {
logx.Errorf("failed to format, %v", err)
}
4 years ago
return nil
}