diff --git a/generator/cmd/create_collector.go b/generator/cmd/create_collector.go index 79744028a68..6c5f3d78703 100644 --- a/generator/cmd/create_collector.go +++ b/generator/cmd/create_collector.go @@ -101,6 +101,21 @@ Type in what the name of collector is, then generator will create a new collecto cobra.CheckErr(err) collectorName = strings.ToLower(collectorName) + prompt = promptui.Prompt{ + Label: "http_path", + Validate: func(input string) error { + if input == `` { + return errors.New("http_path require") + } + if strings.HasPrefix(input, `/`) { + return errors.New("http_path shouldn't start with '/'") + } + return nil + }, + } + httpPath, err := prompt.Run() + cobra.CheckErr(err) + // read template templates := map[string]string{ collectorName + `_collector.go`: util.ReadTemplate("generator/template/plugin/tasks/api_collector.go-template"), @@ -110,6 +125,7 @@ Type in what the name of collector is, then generator will create a new collecto values := map[string]string{} util.GenerateAllFormatVar(values, `plugin_name`, pluginName) util.GenerateAllFormatVar(values, `collector_data_name`, collectorName) + values[`HttpPath`] = httpPath collectorDataNameUpperCamel := strcase.UpperCamelCase(collectorName) values = util.DetectExistVars(templates, values) println(`vars in template:`, fmt.Sprint(values)) diff --git a/generator/cmd/create_migration.go b/generator/cmd/create_migration.go index 5ec3cc7c548..f963e41067a 100644 --- a/generator/cmd/create_migration.go +++ b/generator/cmd/create_migration.go @@ -77,7 +77,7 @@ If framework passed, generator will create a new migration in models/migrationsc Label: "purpose", Validate: func(input string) error { if input == `` { - return errors.New("purpose requite") + return errors.New("purpose require") } return nil }, diff --git a/generator/cmd/create_plugin.go b/generator/cmd/create_plugin.go index aebfcefd896..59a1ad2f5e3 100644 --- a/generator/cmd/create_plugin.go +++ b/generator/cmd/create_plugin.go @@ -35,7 +35,7 @@ func init() { func pluginNameNotExistValidate(input string) error { if input == `` { - return errors.New("plugin name requite") + return errors.New("plugin name require") } snakeNameReg := regexp.MustCompile(`^[A-Za-z][A-Za-z0-9_]*$`) if !snakeNameReg.MatchString(input) { @@ -56,7 +56,7 @@ func pluginNameNotExistValidate(input string) error { func pluginNameExistValidate(input string) error { if input == `` { - return errors.New("plugin name requite") + return errors.New("plugin name require") } _, err := os.Stat(`plugins/` + input) return err @@ -103,7 +103,7 @@ Type in what the name of plugin is, then generator will create a new plugin in p } prompt := promptui.Select{ - Label: "with_api_client (is this plugin will request HTTP APIs?)", + Label: "with_api_client (Will this plugin request HTTP APIs?)", Items: []string{"Yes", "No"}, } _, withApiClient, err := prompt.Run() @@ -117,7 +117,7 @@ Type in what the name of plugin is, then generator will create a new plugin in p Default: `https://open.example.cn/api/v1`, Validate: func(input string) error { if input == `` { - return errors.New("endpoint requite") + return errors.New("endpoint require") } if !strings.HasPrefix(input, `http`) { return errors.New("endpoint should start with http") diff --git a/generator/cmd/e2e_raw_create.go b/generator/cmd/e2e_raw_create.go index 9102fde7412..f66eb2d6243 100644 --- a/generator/cmd/e2e_raw_create.go +++ b/generator/cmd/e2e_raw_create.go @@ -64,7 +64,7 @@ Type in what the raw_table is, then generator will export and save in plugins/$p Default: `_raw_`, Validate: func(input string) error { if input == `` { - return errors.New("raw_table_name requite") + return errors.New("raw_table_name require") } if !strings.HasPrefix(input, `_raw_`) { return errors.New("raw_table_name should start with `_raw_`") @@ -82,7 +82,7 @@ Type in what the raw_table is, then generator will export and save in plugins/$p Default: rawTableName + `.csv`, Validate: func(input string) error { if input == `` { - return errors.New("csv_file_name requite") + return errors.New("csv_file_name require") } if !strings.HasSuffix(input, `.csv`) { return errors.New("csv_file_name should end with `.csv`") diff --git a/generator/template/plugin/tasks/api_collector.go-template b/generator/template/plugin/tasks/api_collector.go-template index c744801d144..055b11d72b0 100644 --- a/generator/template/plugin/tasks/api_collector.go-template +++ b/generator/template/plugin/tasks/api_collector.go-template @@ -49,7 +49,7 @@ func Collect{{ .CollectorDataName }}(taskCtx core.SubTaskContext) error { Incremental: false, Input: iterator, // TODO write which api would you want request - UrlTemplate: "/example/", + UrlTemplate: "{{ .HttpPath }}", Query: func(reqData *helper.RequestData) (url.Values, error) { query := url.Values{} input := reqData.Input.(*helper.DatePair)