Skip to content

Commit

Permalink
fixed:Issue #[4] by [GrantZheng]: [new service with the name as first…
Browse files Browse the repository at this point in the history
… letter capital or Camel].
  • Loading branch information
GrantZheng committed May 25, 2020
1 parent 94a4659 commit a85f301
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions generator/generate_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2202,15 +2202,15 @@ func (g *generateCmd) generateCancelInterrupt() {
}
}
func (g *generateCmd) generateCmdMain() error {
mainDest := fmt.Sprintf(viper.GetString("gk_cmd_path_format"), g.name)
mainDest := fmt.Sprintf(viper.GetString("gk_cmd_path_format"), utils.ToLowerSnakeCase(g.name))
mainFilePath := path.Join(mainDest, "main.go")
g.CreateFolderStructure(mainDest)
if b, err := g.fs.Exists(mainFilePath); err != nil {
return err
} else if b {
return nil
}
cmdSvcImport, err := utils.GetCmdServiceImportPath(g.name)
cmdSvcImport, err := utils.GetCmdServiceImportPath(utils.ToLowerSnakeCase(g.name))
if err != nil {
return err
}
Expand Down
10 changes: 7 additions & 3 deletions generator/new_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,20 @@ func (g *NewService) Generate() error {
}

func (g *NewService) genModule() error {
exist, _ := g.fs.Exists(g.name + "/go.mod")
prjName := utils.ToLowerSnakeCase(g.name)
exist, _ := g.fs.Exists(prjName + "/go.mod")
if exist {
return nil
}

moduleName := g.name
moduleName := prjName
if viper.GetString("n_s_module") != "" {
moduleName = viper.GetString("n_s_module")
moduleNameSlice := strings.Split(moduleName, "/")
moduleNameSlice[len(moduleNameSlice) - 1] = utils.ToLowerSnakeCase(moduleNameSlice[len(moduleNameSlice) - 1])
moduleName = strings.Join(moduleNameSlice, "/")
}
cmdStr := "cd " + g.name + " && go mod init " + moduleName
cmdStr := "cd " + prjName + " && go mod init " + moduleName
cmd := exec.Command("sh", "-c", cmdStr)
_, err := cmd.Output()
return err
Expand Down
2 changes: 1 addition & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func getImportPath(name string, key string) (string, error) {

func getModNameFromModFile(name string) (string, error) {
modFile := "go.mod"
filePath := name + "/" + modFile
filePath := ToLowerSnakeCase(name) + "/" + modFile
exists, _ := fs.Get().Exists(filePath)
var modFileInParentLevel bool
if exists == false {
Expand Down

0 comments on commit a85f301

Please sign in to comment.