Update goclt dart gen: Add scheme config and content-type header (#2987)

Co-authored-by: zhoumingji <zhoumingji@cmsr.chinamobile.com>
This commit is contained in:
Snake
2023-03-08 23:40:55 +08:00
committed by GitHub
parent a2592a17e9
commit e136deb3a7
4 changed files with 36 additions and 17 deletions

View File

@@ -19,6 +19,8 @@ var (
VarStringLegacy bool
// VarStringHostname defines the hostname.
VarStringHostname string
// VarStringSchema defines the scheme.
VarStringScheme string
)
// DartCommand create dart network request code
@@ -27,6 +29,7 @@ func DartCommand(_ *cobra.Command, _ []string) error {
dir := VarStringDir
isLegacy := VarStringLegacy
hostname := VarStringHostname
scheme := VarStringScheme
if len(apiFile) == 0 {
return errors.New("missing -api")
}
@@ -37,6 +40,10 @@ func DartCommand(_ *cobra.Command, _ []string) error {
fmt.Println("you could use '-hostname' flag to specify your server hostname")
hostname = "go-zero.dev"
}
if len(scheme) == 0 {
fmt.Println("you could use '-scheme' flag to specify your server scheme")
scheme = "http"
}
api, err := parser.Parse(apiFile)
if err != nil {
@@ -54,7 +61,7 @@ func DartCommand(_ *cobra.Command, _ []string) error {
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))
logx.Must(genVars(dir+"vars/", isLegacy, scheme, hostname))
if err := formatDir(dir); err != nil {
logx.Errorf("failed to format, %v", err)
}