Documentation
¶
Index ¶
- Constants
- Variables
- func AddCmd(cmd *cobra.Command)
- func CopyDir(src string, dst string) error
- func CopyFile(src, dst string) error
- func CreateDirIfNotExists(dirPath string)
- func DirPath(dirname string) string
- func EnsureBinary(binary string)
- func EnsureEmptyDir(dirname string)
- func Execute() error
- func HasBinary(binary string) bool
- func HasDirectory(dirPath string) bool
- func ParseTemplate(tmplData map[string]interface{}, fileContents string, funcMap template.FuncMap) (string, error)
- func RemoveDirs(dirPath string, dirNames []string)
- func RunCommand(dirPath string, command string, args ...string)
- func ScanStr(input *string, label string)
- type CommandGenerator
- type Commander
- type DBTag
- type DBTagBuilder
- type FormConfig
- type FormField
- type FormGenerator
- type Gen
- type Generator
- type HandlerConfig
- type HandlerField
- type HandlerGenerator
- type InputConfig
- type InputField
- type InputGenerator
- type MigrationConfig
- type MigrationField
- type MigrationGenerator
- type ModelConfig
- type ModelField
- type ModelGenerator
- type PackagePathGetter
- type Replacable
- type RepoConfig
- type RepoGenerator
- type StubGetter
- type Tag
- type ValidateFunc
Constants ¶
View Source
const ( RelationOneToOne = "one_to_one" RelationOneToMany = "one_to_many" RelationManyToOne = "many_to_one" RelationManyToMany = "many_to_many" )
Variables ¶
View Source
var CommonModelFields = []*ModelField{ { Name: "id", Type: "uint64", Required: true, Primary: true, }, { Name: "created_at", Type: "time.Time", Required: true, }, { Name: "updated_at", Type: "time.Time", Required: true, }, { Name: "deleted_at", Type: "time.Time", Required: true, }, }
View Source
var In = func(allowList []string, message string, validators ...ValidateFunc) ValidateFunc { return func(input string) error { if slices.Contains(allowList, strings.ToLower(input)) { if message == "" { return errors.New(fmt.Sprintf("input must contain %s", strings.Join(allowList, ","))) } return errors.New(message) } for _, v := range validators { if err := v(input); err != nil { return err } } return nil } }
View Source
var NotIn = func(ignoreList []string, message string, validators ...ValidateFunc) ValidateFunc { return func(input string) error { if slices.Contains(ignoreList, strings.ToLower(input)) { if message == "" { return errors.New(fmt.Sprintf("input must not contain %s", strings.Join(ignoreList, ","))) } return errors.New(message) } for _, v := range validators { if err := v(input); err != nil { return err } } return nil } }
View Source
var SnakeCase = func(input string) error { if len(input) == 0 { return errors.New("input cannot be empty") } if len(input) > 0 && input[0] < 'a' || input[0] > 'z' { return errors.New("field name must start with a lowercase letter") } for _, c := range input { if c < 'a' || c > 'z' { if c < '0' || c > '9' { if c != '_' { return errors.New("field name must contain only lowercase letters, numbers, and underscores") } } } } return nil }
View Source
var SnakeCaseEmptyAllowed = func(input string) error { if len(input) == 0 { return nil } if len(input) > 0 && input[0] < 'a' || input[0] > 'z' { return errors.New("field name must start with a lowercase letter") } for _, c := range input { if c < 'a' || c > 'z' { if c < '0' || c > '9' { if c != '_' { return errors.New("field name must contain only lowercase letters, numbers, and underscores") } } } } return nil }
View Source
var UiDataTypeMap = map[string]string{ "text": reflect.String.String(), "textarea": reflect.String.String(), "integer": reflect.Uint.String(), "decimal": reflect.Float64.String(), "boolean": reflect.Bool.String(), "radio": reflect.String.String(), "checkbox": reflect.String.String(), "dropdown": reflect.String.String(), "date": "time.Time", "time": "time.Time", "file": reflect.String.String(), }
View Source
var UiDbTypeMap = map[string]string{
"text": "string",
"textarea": "text",
"integer": "unsignedBigInt",
"decimal": "decimal",
"boolean": "boolean",
"radio": "string",
"checkbox": "string",
"dropdown": "string",
"date": "dateTime",
"time": "time",
"file": "string",
}
Functions ¶
func CreateDirIfNotExists ¶ added in v0.1.10
func CreateDirIfNotExists(dirPath string)
CreateDirIfNotExists creates a directory if it does not exist
func EnsureBinary ¶ added in v0.1.10
func EnsureBinary(binary string)
EnsureBinary ensures the git binary is present in the system
func EnsureEmptyDir ¶ added in v0.1.10
func EnsureEmptyDir(dirname string)
EnsureEmptyDir ensures the directory in which the project should be created is empty
func HasDirectory ¶ added in v0.1.10
HasDirectory returns true if a directory exists and false otherwise
func ParseTemplate ¶
func RemoveDirs ¶ added in v0.1.10
RemoveDirs removes the list of given directories
func RunCommand ¶ added in v0.1.10
RunCommand runs a command in a specific directory
Types ¶
type CommandGenerator ¶
type CommandGenerator interface { Generator PackagePathGetter StubGetter Commander }
type DBTagBuilder ¶
type DBTagBuilder struct {
// contains filtered or unexported fields
}
func NewDBTagBuilder ¶
func NewDBTagBuilder(tags []*DBTag, driverName string) *DBTagBuilder
func (*DBTagBuilder) Add ¶
func (mtb *DBTagBuilder) Add(name, argument string) *DBTagBuilder
func (*DBTagBuilder) Build ¶
func (mtb *DBTagBuilder) Build() string
type FormConfig ¶
type FormGenerator ¶
type FormGenerator struct {
// contains filtered or unexported fields
}
func NewFormGenerator ¶
func NewFormGenerator(mc *FormConfig) *FormGenerator
func (*FormGenerator) Generate ¶
func (fg *FormGenerator) Generate(appendable ...[]byte) error
func (*FormGenerator) GetPackagePath ¶
func (fg *FormGenerator) GetPackagePath() string
func (*FormGenerator) GetReplacables ¶
func (fg *FormGenerator) GetReplacables() []*Replacable
func (*FormGenerator) GetStub ¶
func (fg *FormGenerator) GetStub() string
type HandlerConfig ¶
type HandlerConfig struct {
Name string
}
type HandlerField ¶
type HandlerField struct {
Name string
}
type HandlerGenerator ¶
type HandlerGenerator struct {
// contains filtered or unexported fields
}
func NewHandlerGenerator ¶
func NewHandlerGenerator(mc *HandlerConfig) *HandlerGenerator
func (*HandlerGenerator) Command ¶
func (hg *HandlerGenerator) Command() *cobra.Command
func (*HandlerGenerator) Generate ¶
func (hg *HandlerGenerator) Generate(appendable ...[]byte) error
func (*HandlerGenerator) GetPackagePath ¶
func (hg *HandlerGenerator) GetPackagePath() string
func (*HandlerGenerator) GetStub ¶
func (hg *HandlerGenerator) GetStub() string
type InputConfig ¶
type InputConfig struct { Name string Fields []*InputField }
type InputField ¶
type InputGenerator ¶
type InputGenerator struct {
// contains filtered or unexported fields
}
func NewInputGenerator ¶
func NewInputGenerator(mc *InputConfig) *InputGenerator
func (*InputGenerator) Command ¶
func (ig *InputGenerator) Command() *cobra.Command
func (*InputGenerator) Generate ¶
func (ig *InputGenerator) Generate(appendable ...[]byte) error
func (*InputGenerator) GetPackagePath ¶
func (ig *InputGenerator) GetPackagePath() string
func (*InputGenerator) GetStub ¶
func (ig *InputGenerator) GetStub() string
type MigrationConfig ¶
type MigrationField ¶
type MigrationGenerator ¶
type MigrationGenerator struct { Timestamps bool // contains filtered or unexported fields }
func NewMigrationGenerator ¶
func NewMigrationGenerator(mc *MigrationConfig) *MigrationGenerator
func (*MigrationGenerator) BumpVersion ¶
func (mg *MigrationGenerator) BumpVersion() *MigrationGenerator
func (*MigrationGenerator) Command ¶
func (mg *MigrationGenerator) Command() *cobra.Command
func (*MigrationGenerator) Generate ¶
func (mg *MigrationGenerator) Generate(appendable ...[]byte) error
func (*MigrationGenerator) GetPackagePath ¶
func (mg *MigrationGenerator) GetPackagePath() string
func (*MigrationGenerator) GetStub ¶
func (mg *MigrationGenerator) GetStub() string
type ModelConfig ¶
type ModelConfig struct { Name string Fields []*ModelField }
type ModelField ¶
type ModelGenerator ¶
type ModelGenerator struct {
// contains filtered or unexported fields
}
func NewModelGenerator ¶
func NewModelGenerator(mc *ModelConfig) *ModelGenerator
func (*ModelGenerator) Command ¶
func (mg *ModelGenerator) Command() *cobra.Command
func (*ModelGenerator) Generate ¶
func (mg *ModelGenerator) Generate(appendable ...[]byte) error
func (*ModelGenerator) GetPackagePath ¶
func (mg *ModelGenerator) GetPackagePath() string
func (*ModelGenerator) GetStub ¶
func (mg *ModelGenerator) GetStub() string
type PackagePathGetter ¶
type PackagePathGetter interface {
GetPackagePath() string
}
type Replacable ¶
type Replacable struct { Placeholder string Value interface{} }
type RepoConfig ¶ added in v0.1.13
type RepoConfig struct {
Name string
}
type RepoGenerator ¶ added in v0.1.13
type RepoGenerator struct {
// contains filtered or unexported fields
}
func NewRepoGenerator ¶ added in v0.1.13
func NewRepoGenerator(rc *RepoConfig) *RepoGenerator
func (*RepoGenerator) Command ¶ added in v0.1.13
func (rg *RepoGenerator) Command() *cobra.Command
func (*RepoGenerator) Generate ¶ added in v0.1.13
func (rg *RepoGenerator) Generate(appendable ...[]byte) error
func (*RepoGenerator) GetPackagePath ¶ added in v0.1.13
func (rg *RepoGenerator) GetPackagePath() string
func (*RepoGenerator) GetStub ¶ added in v0.1.13
func (rg *RepoGenerator) GetStub() string
type StubGetter ¶
type StubGetter interface {
GetStub() string
}
type ValidateFunc ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.