-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: migrate log to logrus
- Loading branch information
Hidayat Hamir
committed
Feb 7, 2024
1 parent
ab80403
commit 0aa0067
Showing
9 changed files
with
221 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package template | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"text/template" | ||
|
||
"github.com/iancoleman/strcase" | ||
) | ||
|
||
func GetInjectionTemplate(domain string, moduleName string) (string, error) { | ||
injectionConfig := NewInjectionConfig(domain) | ||
injectionConfig.ModuleName = moduleName | ||
|
||
injectionTemplate, err := template.New("injectionTemplate").Parse(injectionTemplate) | ||
if err != nil { | ||
return "", fmt.Errorf("err parse template injectionTemplate: %v", err) | ||
} | ||
|
||
var templateBuf bytes.Buffer | ||
if err = injectionTemplate.Execute(&templateBuf, injectionConfig); err != nil { | ||
return "", fmt.Errorf("err create template: %v", err) | ||
} | ||
|
||
return templateBuf.String(), nil | ||
} | ||
|
||
type InjectionConfig struct { | ||
DomainPascalCase string | ||
DomainCamelCase string | ||
ModuleName string | ||
} | ||
|
||
func NewInjectionConfig(domain string) InjectionConfig { | ||
return InjectionConfig{ | ||
DomainPascalCase: strcase.ToCamel(domain), | ||
DomainCamelCase: strcase.ToLowerCamel(domain), | ||
} | ||
} | ||
|
||
var injectionTemplate = `package router | ||
import ( | ||
"gorm.io/gorm" | ||
"{{.ModuleName}}/internal/controller/http" | ||
"{{.ModuleName}}/internal/repository" | ||
"{{.ModuleName}}/internal/service" | ||
) | ||
func get{{.DomainPascalCase}}Controller(db *gorm.DB) *http.{{.DomainPascalCase}}Controller { | ||
{{.DomainCamelCase}}Repository := repository.New{{.DomainPascalCase}}Repository(db) | ||
{{.DomainCamelCase}}Service := service.New{{.DomainPascalCase}}Service({{.DomainCamelCase}}Repository) | ||
{{.DomainCamelCase}}Controller := http.New{{.DomainPascalCase}}Controller({{.DomainCamelCase}}Service) | ||
return {{.DomainCamelCase}}Controller | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package template | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"text/template" | ||
|
||
"github.com/iancoleman/strcase" | ||
) | ||
|
||
func GetInjectionAppendTemplate(domain string) (string, error) { | ||
injectionAppendConfig := NewInjectionConfigAppend(domain) | ||
|
||
injectionAppendTemplate, err := template.New("injectionAppendTemplate").Parse(injectionAppendTemplate) | ||
if err != nil { | ||
return "", fmt.Errorf("err parse template injectionAppendTemplate: %v", err) | ||
} | ||
|
||
var templateBuf bytes.Buffer | ||
if err = injectionAppendTemplate.Execute(&templateBuf, injectionAppendConfig); err != nil { | ||
return "", fmt.Errorf("err create template: %v", err) | ||
} | ||
|
||
return templateBuf.String(), nil | ||
} | ||
|
||
type InjectionConfigAppend struct { | ||
DomainPascalCase string | ||
DomainCamelCase string | ||
} | ||
|
||
func NewInjectionConfigAppend(domain string) InjectionConfigAppend { | ||
return InjectionConfigAppend{ | ||
DomainPascalCase: strcase.ToCamel(domain), | ||
DomainCamelCase: strcase.ToLowerCamel(domain), | ||
} | ||
} | ||
|
||
var injectionAppendTemplate = ` | ||
func get{{.DomainPascalCase}}Controller(db *gorm.DB) *http.{{.DomainPascalCase}}Controller { | ||
{{.DomainCamelCase}}Repository := repository.New{{.DomainPascalCase}}Repository(db) | ||
{{.DomainCamelCase}}Service := service.New{{.DomainPascalCase}}Service({{.DomainCamelCase}}Repository) | ||
{{.DomainCamelCase}}Controller := http.New{{.DomainPascalCase}}Controller({{.DomainCamelCase}}Service) | ||
return {{.DomainCamelCase}}Controller | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,5 @@ package version | |
import "fmt" | ||
|
||
func Version() { | ||
fmt.Println("v0.0.12") | ||
fmt.Println("v0.0.13") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.