Documentation
¶
Index ¶
- Variables
- func BindIntArg(flags *pflag.FlagSet, viper *viper.Viper, a *IntArg) error
- func BindStringArg(flags *pflag.FlagSet, viper *viper.Viper, a *StringArg) error
- func CompileUnixScript(commands []string) string
- func GenerateMigrateSQL(conn *gorm.DB, models ...interface{}) ([]string, error)
- func MakeEnvPairs(envMaps ...map[string]string) []string
- func RandomBytes(size int) []byte
- func RandomID(prefix string) string
- func RandomInt(min, max int64) int64
- func RandomString(length int) string
- func RandomStringFromCharset(length int, charset string) string
- func Wait(ctx context.Context, t time.Duration) error
- type IntArg
- type StringArg
- type StringError
Constants ¶
This section is empty.
Variables ¶
var RandomLower = func(length int) string { return RandomStringFromCharset(length, lowercase) }
Functions ¶
func BindIntArg ¶
BindIntArg binds a int argument to the flagset and viper
func BindStringArg ¶
BindStringArg binds a string argument to the flagset and viper
func CompileUnixScript ¶
CompileUnixScript compiles unix commands into a single shell script which can be executed by shell.
func GenerateMigrateSQL ¶
GenerateMigrateSQL generates DDL SQL for the models.
func MakeEnvPairs ¶
MakeEnvPairs converts string maps to key=value pairs. exec.Command requires envs to be in key=value format.
func RandomBytes ¶
RandomBytes returns a slice of random bytes of the given size.
func RandomID ¶
RandomID generates a random string with xid with a prefix. The result is NOT cryptographically secure.
func RandomString ¶
RandomString returns a random string with the given length.
func RandomStringFromCharset ¶
Types ¶
type IntArg ¶
type IntArg struct { // ArgKey is the key used to bind the flag to viper ArgKey string // FlagName is the name of the flag. If empty, disable loading from flags FlagName string // FlagValue is the default value of the flag FlagValue int FlagUsage string // Env is the environment variable name, if empty, disable loading from env Env string }
IntArg is a struct that represents a int argument
type StringArg ¶
type StringArg struct { // ArgKey is the key used to bind the flag to viper ArgKey string // FlagName is the name of the flag. If empty, disable loading from flags FlagName string // FlagValue is the default value of the flag FlagValue string // FlagUsage is the usage of the flag FlagUsage string // Env is the environment variable name, if empty, disable loading from env Env string }
StringArg is a struct that represents a string argument
type StringError ¶
type StringError string
StringError is a simple error type that implements the error interface. It is useful when you want to return a constant error message.
func (StringError) Error ¶
func (e StringError) Error() string