From 9539ee97329c07ca368a55bda3c7fd0acd399dd3 Mon Sep 17 00:00:00 2001 From: Dao Anh Dung Date: Tue, 30 May 2023 10:20:09 +0700 Subject: [PATCH] Fix bug for without modules --- README.md | 2 +- main.go | 2 +- .../internal/delivery/http/handler.go.tmpl | 2 +- .../internal/repository/repository.go.tmpl | 16 ++++++++++++++++ .../tmpl/internal/usecase/usecase.go.tmpl | 19 +++++++++++++++++++ 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4f778ca..8c92c59 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/main.go b/main.go index 0f0505b..f922064 100644 --- a/main.go +++ b/main.go @@ -9,7 +9,7 @@ import ( ) var ( - version string = "v1.0.5" + version string = "v1.0.6" ) func main() { diff --git a/template/tmpl/internal/delivery/http/handler.go.tmpl b/template/tmpl/internal/delivery/http/handler.go.tmpl index ada998d..fac8ffe 100644 --- a/template/tmpl/internal/delivery/http/handler.go.tmpl +++ b/template/tmpl/internal/delivery/http/handler.go.tmpl @@ -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{ diff --git a/template/tmpl/internal/repository/repository.go.tmpl b/template/tmpl/internal/repository/repository.go.tmpl index c5dd456..2188d69 100644 --- a/template/tmpl/internal/repository/repository.go.tmpl +++ b/template/tmpl/internal/repository/repository.go.tmpl @@ -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}} diff --git a/template/tmpl/internal/usecase/usecase.go.tmpl b/template/tmpl/internal/usecase/usecase.go.tmpl index a72be62..7b66bbd 100644 --- a/template/tmpl/internal/usecase/usecase.go.tmpl +++ b/template/tmpl/internal/usecase/usecase.go.tmpl @@ -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}}