mc

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 5, 2023 License: Apache-2.0 Imports: 7 Imported by: 3

README

The Magic Conch

Go Report Card Build Status License Tags Go Reference

Why don't you ask... the Magic Conch?

Golang snippets.

Document: Go Reference

Documentation

Index

Constants

View Source
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 EnvOr

func EnvOr(key string, defaultValue string) string

EnvOr retrieves the value of the environment variable named by the key.

func Must

func Must(e any)

Must check a value to be nil, panics 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 PointerTo added in v0.0.2

func PointerTo[V any](v V) *V

PointerTo creates a pointer to bool

func PtrTo added in v0.0.2

func PtrTo[V any](v V) *V

func SliceContains added in v0.0.2

func SliceContains[V comparable](slice []V, v V) bool

func StringEnsurePrefix

func StringEnsurePrefix(s string, cut string) string

StringEnsurePrefix returns a string, which is the original string if it has the prefix, or the prefix will be added.

func StringEnsureSuffix

func StringEnsureSuffix(s string, cut string) string

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 StringIsValidEmail(s string) bool

func StringRand

func StringRand(length int) string

StringRand generates random string with specific length.

func StringRandWithCharset

func StringRandWithCharset(length int, charset string) string

StringRandWithCharset generates random string with specific length and charset.

func StringToInt

func StringToInt(s string) int

StringToInt converts a string to an int, errors are ignored

func StringToInt16

func StringToInt16(s string) int16

StringToInt16 converts a string to an int16, errors are ignored

func StringToInt32

func StringToInt32(s string) int32

StringToInt32 converts a string to an int32, errors are ignored

func StringToInt64

func StringToInt64(s string) int64

StringToInt64 converts a string to an int64, errors are ignored

func StringToInt8

func StringToInt8(s string) int8

StringToInt8 converts a string to an int8, errors are ignored

func StringToUint

func StringToUint(s string) uint

StringToUint converts a string to an uint, errors are ignored

func StringToUint16

func StringToUint16(s string) uint16

StringToUint16 converts a string to an uint16, errors are ignored

func StringToUint32

func StringToUint32(s string) uint32

StringToUint32 converts a string to an uint32, errors are ignored

func StringToUint64

func StringToUint64(s string) uint64

StringToUint64 converts a string to an uint64, errors are ignored

func StringToUint8

func StringToUint8(s string) uint8

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

type OpenOrCreateOptions added in v0.0.4

type OpenOrCreateOptions struct {
	Template     string
	TemplatePath string
}

Jump to

Keyboard shortcuts

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