Skip to content

Commit

Permalink
fix: fix some typo and ask http_path in create_collector (apache#2395)
Browse files Browse the repository at this point in the history
Co-authored-by: linyh <yanghui@meri.co>
  • Loading branch information
likyh and likyh committed Jun 30, 2022
1 parent d687626 commit 52ccc54
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
16 changes: 16 additions & 0 deletions generator/cmd/create_collector.go
Expand Up @@ -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"),
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion generator/cmd/create_migration.go
Expand Up @@ -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
},
Expand Down
8 changes: 4 additions & 4 deletions generator/cmd/create_plugin.go
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions generator/cmd/e2e_raw_create.go
Expand Up @@ -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_`")
Expand All @@ -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`")
Expand Down
2 changes: 1 addition & 1 deletion generator/template/plugin/tasks/api_collector.go-template
Expand Up @@ -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)
Expand Down

0 comments on commit 52ccc54

Please sign in to comment.