Skip to content

Commit

Permalink
Merge pull request #13 from dung13890/generate_project
Browse files Browse the repository at this point in the history
Fix bug camelcase
  • Loading branch information
dung13890 authored Jun 6, 2023
2 parents c3172ec + 540e1d1 commit 608d8ff
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ USAGE:
go-base-gen [global options] command [command options] [arguments...]

VERSION:
v1.0.8
v1.0.9

COMMANDS:
project Generate base code for go project use clean architecture
Expand Down
17 changes: 9 additions & 8 deletions cmd/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func NewDomain() *cli.Command {
}

d := &domain{
Domain: strings.ToLower(ctx.String("name")),
Domain: ctx.String("name"),
Project: strings.ToLower(ctx.String("project")),
Module: strings.ToLower(ctx.String("module")),
Path: rltDir,
Expand Down Expand Up @@ -235,15 +235,16 @@ func (d *domain) generateFile(_ context.Context) error {
if err != nil {
return err
}
snakeDomain := utils.ToSnakeCase(d.Domain)
rl := strings.NewReplacer(
"/modules/name/", "/modules/"+d.Module+"/",
"domain.go", d.Domain+".go",
"domain_http.go", d.Domain+"_http.go",
"domain_grpc.go", d.Domain+"_grpc.go",
"domain_dto.go", d.Domain+"_dto.go",
"domain_repo.go", d.Domain+"_repo.go",
"domain_dao.go", d.Domain+"_dao.go",
"domain_uc.go", d.Domain+"_uc.go",
"domain.go", snakeDomain+".go",
"domain_http.go", snakeDomain+"_http.go",
"domain_grpc.go", snakeDomain+"_grpc.go",
"domain_dto.go", snakeDomain+"_dto.go",
"domain_repo.go", snakeDomain+"_repo.go",
"domain_dao.go", snakeDomain+"_dao.go",
"domain_uc.go", snakeDomain+"_uc.go",
)
files := dFilesWithoutModule
if d.Module != "" {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

var (
version string = "v1.0.8"
version string = "v1.0.9"
)

func main() {
Expand Down
14 changes: 14 additions & 0 deletions pkg/utils/string.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package utils

import (
"regexp"
"strings"
)

// ToSnakeCase is a function to convert a string to snake case
func ToSnakeCase(str string) string {
snake := regexp.MustCompile("(.)([A-Z][a-z]+)").ReplaceAllString(str, "${1}_${2}")
snake = regexp.MustCompile("([a-z0-9])([A-Z])").ReplaceAllString(snake, "${1}_${2}")

return strings.ToLower(snake)
}

0 comments on commit 608d8ff

Please sign in to comment.