Skip to content

Commit

Permalink
Merge pull request #11 from dung13890/generate_project
Browse files Browse the repository at this point in the history
Fix bug for without modules
  • Loading branch information
dung13890 authored May 30, 2023
2 parents 624bbf8 + 9539ee9 commit 13ca522
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 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.4
v1.0.6

COMMANDS:
project Generate base code for go project use clean architecture
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.5"
version string = "v1.0.6"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion template/tmpl/internal/delivery/http/handler.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/labstack/echo/v4"
)

// NewHandler will initialize the {{.Module}} module endpoints
// NewHandler will initialize the endpoints
func NewHandler(g *echo.Group, uc *usecase.Usecase) {
// {{.Domain}}Handler will initialize the {{.Domain}}/ resources endpoint
{{.Domain}}Handler := &{{.Domain | capitalize}}Handler{
Expand Down
16 changes: 16 additions & 0 deletions template/tmpl/internal/repository/repository.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,20 @@ Mit License (MIT)
*/}}

{{define "internal/repository/repository.go"}}package repository

import (
"{{.Project}}/internal/domain"
)

// Repository for all repository
type Repository struct {
{{.Domain | capitalize}}R domain.{{.Domain | capitalize}}Repository
}

// NewRepository will create new postgres object
func NewRepository() *Repository {
return &Repository{
{{.Domain | capitalize}}R: &{{.Domain | capitalize}}Repository{},
}
}
{{end}}
19 changes: 19 additions & 0 deletions template/tmpl/internal/usecase/usecase.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,23 @@ Mit License (MIT)
*/}}

{{define "internal/usecase/usecase.go"}}package usecase

import (
"{{.Project}}/internal/domain"
"{{.Project}}/internal/repository"
)

// Usecase for all usecase
type Usecase struct {
{{.Domain | capitalize}}UC domain.{{.Domain | capitalize}}Usecase
}

// NewUsecase implements from interface
func NewUsecase(
repo *repository.Repository,
) *Usecase {
return &Usecase{
{{.Domain | capitalize}}UC: New{{.Domain | capitalize}}Usecase(repo.{{.Domain | capitalize}}R),
}
}
{{end}}

0 comments on commit 13ca522

Please sign in to comment.