Documentation ¶
Index ¶
Constants ¶
View Source
const ( CommandContextCfgKey CommandContextKey = "cfg" CommandContextCfgKeyDB = CommandContextCfgKey + ".db" CommandContextCfgKeyLog = CommandContextCfgKey + ".log" CommandContextCfgKeyAppInfo = CommandContextCfgKey + ".appInfo" CommandContextCfgKeyStage = CommandContextCfgKey + ".stage" )
View Source
const ( CommandContextObjectKey CommandContextKey = "obj" CommandContextObjectKeySeeder = CommandContextObjectKey + ".seeder" CommandContextObjectKeyConfig = CommandContextObjectKey + ".config" )
View Source
const ( CmdFailureCode = 1 CmdErrStrFormat = "%s %s error: %w" )
Variables ¶
View Source
var ( ErrNoMethodFound = errors.New("seed method is not exists") ErrSeedIsDisabled = errors.New("seed method is disabled in config") ErrSeedClassNameNotRegistered = errors.New("seed class name not registered") ErrSeedClassIsNotValid = errors.New("seed class name not valid") ErrSeedClassNotImplementInterface = errors.New("seed class name not implements commands.SeedInterface") ErrBadContextValue = errors.New("context value is empty (not passed as pointer?) or don't implement interface") )
View Source
var ( SeedCmd = &cobra.Command{ Use: "seed", Short: "Database seeding command", ValidArgs: []string{"run", "run-all", "list"}, Args: cobra.MinimumNArgs(1), } SeedRunAllCmd = &cobra.Command{ Use: "run-all", RunE: seedRunAll, } SeedRunCmd = &cobra.Command{ Use: "run", Args: cobra.MinimumNArgs(1), RunE: seedRun, } )
SeedCmd is a database seeding wrapper command.
View Source
var MigrateCmd = &cobra.Command{ Use: "migrate", Short: "Database migrations command", ValidArgs: []string{"up", "up-by-one", "up-to", "create", "down", "down-to", "fix", "redo", "reset", "status", "version"}, Args: cobra.MinimumNArgs(1), RunE: migrate, }
MigrateCmd is a github.com/pressly/goose database migrate wrapper command.
View Source
var VersionCmd = &cobra.Command{ Use: "version", Short: "Print the version number", RunE: func(cmd *cobra.Command, args []string) error { appInfo, ok := cmd.Context().Value(CommandContextCfgKeyAppInfo).(contracts.ApplicationInfoCfgInterface) if !ok { return fmt.Errorf("%w: app info config (cfg.appInfo)", ErrBadContextValue) } cmd.Println(appInfo.GetVersion()) return nil }, }
Functions ¶
func SeedMethodType ¶
func SeedMethodType(seed SeedInterface) reflect.Type
SeedMethodType checks SeedInterface implementation and returns Seed object reflect.Type.
Types ¶
type CommandContextKey ¶
type CommandContextKey string
type SeedInterface ¶
type SeedInterface interface { Enabled() bool Name() string Seed() error SetRepo(r interface{}) SetCfg(c cfgstructs.SeedInfo) }
type Seeder ¶
type Seeder struct {
// contains filtered or unexported fields
}
func (Seeder) GetMethods ¶
func (s Seeder) GetMethods() map[string]SeedInterface
type SeederInterface ¶
type SeederInterface interface { GetMethods() map[string]SeedInterface GetMethod(name string) (SeedInterface, error) SeedsList() []string }
func NewSeeder ¶
func NewSeeder(cfg cfgstructs.SeedingCfg, seeds map[string]reflect.Type, repo interface{}) (SeederInterface, error)
NewSeeder initiates new Seeder object.
Source Files ¶
Click to show internal directories.
Click to hide internal directories.