util

package
v0.0.0-...-ed06f05 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2025 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RandomLower = func(length int) string {
	return RandomStringFromCharset(length, lowercase)
}

Functions

func BindIntArg

func BindIntArg(flags *pflag.FlagSet, viper *viper.Viper, a *IntArg) error

BindIntArg binds a int argument to the flagset and viper

func BindStringArg

func BindStringArg(flags *pflag.FlagSet, viper *viper.Viper, a *StringArg) error

BindStringArg binds a string argument to the flagset and viper

func CompileUnixScript

func CompileUnixScript(commands []string) string

CompileUnixScript compiles unix commands into a single shell script which can be executed by shell.

func GenerateMigrateSQL

func GenerateMigrateSQL(conn *gorm.DB, models ...interface{}) ([]string, error)

GenerateMigrateSQL generates DDL SQL for the models.

func MakeEnvPairs

func MakeEnvPairs(envMaps ...map[string]string) []string

MakeEnvPairs converts string maps to key=value pairs. exec.Command requires envs to be in key=value format.

func RandomBytes

func RandomBytes(size int) []byte

RandomBytes returns a slice of random bytes of the given size.

func RandomID

func RandomID(prefix string) string

RandomID generates a random string with xid with a prefix. The result is NOT cryptographically secure.

func RandomInt

func RandomInt(min, max int64) int64

RandomInt returns a random int64 in [0, max).

func RandomString

func RandomString(length int) string

RandomString returns a random string with the given length.

func RandomStringFromCharset

func RandomStringFromCharset(length int, charset string) string

func Wait

func Wait(ctx context.Context, t time.Duration) error

Wait waits for the given duration or context to be done.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL