Add the ability to fully customize jet generated files.
This commit is contained in:
parent
caa81930dc
commit
8864667f47
40 changed files with 2274 additions and 882 deletions
8
internal/utils/throw/throw.go
Normal file
8
internal/utils/throw/throw.go
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package throw
|
||||
|
||||
// OnError will panic if err is not nill
|
||||
func OnError(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
|
@ -10,7 +10,6 @@ import (
|
|||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// ToGoIdentifier converts database to Go identifier.
|
||||
|
|
@ -18,16 +17,6 @@ func ToGoIdentifier(databaseIdentifier string) string {
|
|||
return snaker.SnakeToCamel(replaceInvalidChars(databaseIdentifier))
|
||||
}
|
||||
|
||||
// ToGoEnumValueIdentifier converts enum value name to Go identifier name.
|
||||
func ToGoEnumValueIdentifier(enumName, enumValue string) string {
|
||||
enumValueIdentifier := ToGoIdentifier(enumValue)
|
||||
if !unicode.IsLetter([]rune(enumValueIdentifier)[0]) {
|
||||
return ToGoIdentifier(enumName) + enumValueIdentifier
|
||||
}
|
||||
|
||||
return enumValueIdentifier
|
||||
}
|
||||
|
||||
// ToGoFileName converts database identifier to Go file name.
|
||||
func ToGoFileName(databaseIdentifier string) string {
|
||||
return strings.ToLower(replaceInvalidChars(databaseIdentifier))
|
||||
|
|
@ -35,7 +24,11 @@ func ToGoFileName(databaseIdentifier string) string {
|
|||
|
||||
// SaveGoFile saves go file at folder dir, with name fileName and contents text.
|
||||
func SaveGoFile(dirPath, fileName string, text []byte) error {
|
||||
newGoFilePath := filepath.Join(dirPath, fileName) + ".go"
|
||||
newGoFilePath := filepath.Join(dirPath, fileName)
|
||||
|
||||
if !strings.HasSuffix(newGoFilePath, ".go") {
|
||||
newGoFilePath += ".go"
|
||||
}
|
||||
|
||||
file, err := os.Create(newGoFilePath)
|
||||
|
||||
|
|
@ -160,13 +153,6 @@ func MustBeInitializedPtr(val interface{}, errorStr string) {
|
|||
}
|
||||
}
|
||||
|
||||
// PanicOnError panics if err is not nil
|
||||
func PanicOnError(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// ErrorCatch is used in defer to recover from panics and to set err
|
||||
func ErrorCatch(err *error) {
|
||||
recovered := recover()
|
||||
|
|
|
|||
|
|
@ -25,11 +25,6 @@ func TestToGoIdentifier(t *testing.T) {
|
|||
require.Equal(t, ToGoIdentifier("My-Table"), "MyTable")
|
||||
}
|
||||
|
||||
func TestToGoEnumValueIdentifier(t *testing.T) {
|
||||
require.Equal(t, ToGoEnumValueIdentifier("enum_name", "enum_value"), "EnumValue")
|
||||
require.Equal(t, ToGoEnumValueIdentifier("NumEnum", "100"), "NumEnum100")
|
||||
}
|
||||
|
||||
func TestErrorCatchErr(t *testing.T) {
|
||||
var err error
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue