Documentation ¶
Index ¶
- Constants
- func EnsureFileExists(filePath string, optionFuncs ...OpenOrCreateOptionFunc) error
- func EnvOr(key string, defaultValue string) string
- func Must(e any)
- func OpenOrCreate(filePath string, optionFuncs ...OpenOrCreateOptionFunc) (*os.File, error)
- func PointerTo[V any](v V) *V
- func PtrTo[V any](v V) *V
- func SliceContains[V comparable](slice []V, v V) bool
- func StringEnsurePrefix(s string, cut string) string
- func StringEnsureSuffix(s string, cut string) string
- func StringIsValidEmail(s string) bool
- func StringRand(length int) string
- func StringRandWithCharset(length int, charset string) string
- func StringToInt(s string) int
- func StringToInt16(s string) int16
- func StringToInt32(s string) int32
- func StringToInt64(s string) int64
- func StringToInt8(s string) int8
- func StringToUint(s string) uint
- func StringToUint16(s string) uint16
- func StringToUint32(s string) uint32
- func StringToUint64(s string) uint64
- func StringToUint8(s string) uint8
- func ValueOr[V comparable](v V, alternatives ...V) V
- func VarOr[V comparable](v V, alternatives ...V) V
- type OpenOrCreateOptionFunc
- type OpenOrCreateOptions
Constants ¶
const (
// CharsetDefault is the charset for StringRand
CharsetDefault = "abcdefghijklmnopqrstuvwxyzsABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
)
Variables ¶
This section is empty.
Functions ¶
func EnsureFileExists ¶ added in v0.0.4
func EnsureFileExists(filePath string, optionFuncs ...OpenOrCreateOptionFunc) error
EnsureFileExists ensures the file exist, creates it with a template if not.
func OpenOrCreate ¶ added in v0.0.4
func OpenOrCreate(filePath string, optionFuncs ...OpenOrCreateOptionFunc) (*os.File, error)
OpenOrCreate opens the file, creates it with a template if not.
func SliceContains ¶ added in v0.0.2
func SliceContains[V comparable](slice []V, v V) bool
func StringEnsurePrefix ¶
StringEnsurePrefix returns a string, which is the original string if it has the prefix, or the prefix will be added.
func StringEnsureSuffix ¶
StringEnsureSuffix returns a string, which is the original string if it has the suffix, or the suffix will be appended.
func StringIsValidEmail ¶ added in v0.0.4
func StringRand ¶
StringRand generates random string with specific length.
func StringRandWithCharset ¶
StringRandWithCharset generates random string with specific length and charset.
func StringToInt ¶
StringToInt converts a string to an int, errors are ignored
func StringToInt16 ¶
StringToInt16 converts a string to an int16, errors are ignored
func StringToInt32 ¶
StringToInt32 converts a string to an int32, errors are ignored
func StringToInt64 ¶
StringToInt64 converts a string to an int64, errors are ignored
func StringToInt8 ¶
StringToInt8 converts a string to an int8, errors are ignored
func StringToUint ¶
StringToUint converts a string to an uint, errors are ignored
func StringToUint16 ¶
StringToUint16 converts a string to an uint16, errors are ignored
func StringToUint32 ¶
StringToUint32 converts a string to an uint32, errors are ignored
func StringToUint64 ¶
StringToUint64 converts a string to an uint64, errors are ignored
func StringToUint8 ¶
StringToUint8 converts a string to an uint8, errors are ignored
func ValueOr ¶ added in v0.0.4
func ValueOr[V comparable](v V, alternatives ...V) V
ValueOr returns the default value if the value is empty
func VarOr ¶ added in v0.0.3
func VarOr[V comparable](v V, alternatives ...V) V
Types ¶
type OpenOrCreateOptionFunc ¶ added in v0.0.4
type OpenOrCreateOptionFunc func(o *OpenOrCreateOptions) error
func OpenOrCreateWithTemplate ¶ added in v0.0.4
func OpenOrCreateWithTemplate(template string) OpenOrCreateOptionFunc
func OpenOrCreateWithTemplatePath ¶ added in v0.0.4
func OpenOrCreateWithTemplatePath(templatePath string) OpenOrCreateOptionFunc