Documentation ¶
Overview ¶
Package profile provides a simple way to manage runtime/pprof profiling of your Go application.
Package randutil provides various convenience functions for dealing with random numbers and strings.
Index ¶
- Constants
- Variables
- func AESDecrypt(key, text []byte) ([]byte, error)
- func AESEncrypt(key, text []byte) ([]byte, error)
- func AlphaString(n int) (string, error)
- func AlphaStringRange(min, max int) (string, error)
- func ChoiceInt(choices []int) (int, error)
- func ChoiceString(choices []string) (string, error)
- func Copy(src, dest string) error
- func CopyExportedStructFields(src, dstPtr interface{}) (copied int)
- func CopyExportedStructFieldsVal(src, dst reflect.Value) (copied int)
- func Expand(template string, match map[string]string, subs ...string) string
- func ExportedStructFields(v reflect.Value) map[string]reflect.Value
- func Fields(obj interface{}) ([]string, error)
- func FileMTime(file string) (int64, error)
- func FileSize(file string) (int64, error)
- func GetField(obj interface{}, name string) (interface{}, error)
- func GetFieldKind(obj interface{}, name string) (reflect.Kind, error)
- func GetFieldTag(obj interface{}, fieldName, tagKey string) (string, error)
- func GetMethods(v interface{}) map[string][]string
- func GetMidnightSeconds() int64
- func HasField(obj interface{}, name string) (bool, error)
- func HexStr2int(hexStr string) (int, error)
- func HumaneFileSize(s uint64) string
- func Int2HexStr(num int) (hex string)
- func Int64ToIp(ip int64) string
- func IntRange(min, max int) (int, error)
- func Invoke(any interface{}, name string, args ...interface{}) (result []reflect.Value)
- func IpToInt64(ip string) (int64, error)
- func IsDir(dir string) bool
- func IsEmptyValue(v interface{}) bool
- func IsExist(path string) bool
- func IsExportedField(structField reflect.StructField) bool
- func IsExportedName(name string) bool
- func IsFile(filePath string) bool
- func IsLetter(l uint8) bool
- func IsSliceContainsStr(slice []string, str string) bool
- func Items(obj interface{}) (map[string]interface{}, error)
- func PowInt(x int, y int) int
- func RandomCreateBytes(n int, alphabets ...byte) []byte
- func Reverse(s string) string
- func SetField(obj interface{}, name string, value interface{}) error
- func Start(cfg *Config) interface{ ... }
- func String(n int, charset string) (string, error)
- func StringRange(min, max int, charset string) (string, error)
- func Tags(obj interface{}, key string) (map[string]string, error)
- func ToSnakeCase(str string) string
- func ToStr(value interface{}, args ...int) (s string)
- func WriteFile(filename string, data []byte) error
- type Choice
- type Config
- type StrTo
- type Trie
- type TrieNode
Constants ¶
const ( Byte = 1 KByte = Byte * 1024 MByte = KByte * 1024 GByte = MByte * 1024 TByte = GByte * 1024 PByte = TByte * 1024 EByte = PByte * 1024 )
Storage unit constants.
const ( // Set of characters to use for generating random strings Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" Numerals = "1234567890" Alphanumeric = Alphabet + Numerals Ascii = Alphanumeric + "~!@#$%^&*()-_+={}[]\\|<,>.?/\"';:`" )
Variables ¶
var ( CPUProfile = &Config{ CPUProfile: true, } MemProfile = &Config{ MemProfile: true, } BlockProfile = &Config{ BlockProfile: true, } )
var MinMaxError = errors.New("Min cannot be greater than max.")
Functions ¶
func AESDecrypt ¶
AESDecrypt decrypts text and given key with AES.
func AESEncrypt ¶
AESEncrypt encrypts text and given key with AES.
func AlphaString ¶
AlphaString returns a random alphanumeric string n characters long.
func AlphaStringRange ¶
AlphaRange returns a random alphanumeric string at least min and no more than max characters long.
func ChoiceString ¶
ChoiceString returns a random selection from an array of strings.
func CopyExportedStructFields ¶
func CopyExportedStructFields(src, dstPtr interface{}) (copied int)
CopyExportedStructFields copies all exported struct fields from src that are assignable to their name siblings at dstPtr to dstPtr. src can be a struct or a pointer to a struct, dstPtr must be a pointer to a struct.
func Fields ¶
Fields returns the struct fields names list. obj can whether be a structure or pointer to structure.
func GetField ¶
GetField returns the value of the provided obj field. obj can whether be a structure or pointer to structure.
func GetFieldKind ¶
GetFieldKind returns the kind of the provided obj field. obj can whether be a structure or pointer to structure.
func GetFieldTag ¶
GetFieldTag returns the provided obj field tag value. obj can whether be a structure or pointer to structure.
func GetMethods ¶
func HasField ¶
HasField checks if the provided field name is part of a struct. obj can whether be a structure or pointer to structure.
func HexStr2int ¶
HexStr2int converts hex format string to decimal number.
func HumaneFileSize ¶
HumaneFileSize calculates the file size and generate user-friendly string.
func Int2HexStr ¶
Int2HexStr converts decimal number to hex format string.
func IsDir ¶
IsDir returns true if given path is a directory, or returns false when it's a file or does not exist.
func IsEmptyValue ¶
func IsEmptyValue(v interface{}) bool
func IsExist ¶
IsExist checks whether a file or directory exists. It returns false when the file or directory does not exist.
func IsExportedField ¶
func IsExportedField(structField reflect.StructField) bool
func IsExportedName ¶
func IsFile ¶
IsFile returns true if given path is a file, or returns false when it's a directory or does not exist.
func IsSliceContainsStr ¶
func Items ¶
Items returns the field - value struct pairs as a map. obj can whether be a structure or pointer to structure.
func RandomCreateBytes ¶
RandomCreateBytes generate random []byte by specify chars.
func SetField ¶
SetField sets the provided obj field with provided value. obj param has to be a pointer to a struct, otherwise it will soundly fail. Provided value type should match with the struct field you're trying to set.
func Start ¶
func Start(cfg *Config) interface { Stop() }
Start starts a new profiling session configured using *Config. The caller should call the Stop method on the value returned to cleanly stop profiling. Passing a nil *Config is the same as passing a *Config with defaults chosen.
func StringRange ¶
StringRange returns a random string at least min and no more than max characters long, composed of entitites from charset.
func Tags ¶
Tags lists the struct tag fields. obj can whether be a structure or pointer to structure.
func ToSnakeCase ¶
ToSnakeCase can convert all upper case characters in a string to underscore format.
Some samples.
"FirstName" => "first_name" "HTTPServer" => "http_server" "NoHTTPS" => "no_https" "GO_PATH" => "go_path" "GO PATH" => "go_path" // space is converted to underscore. "GO-PATH" => "go_path" // hyphen is converted to underscore.
Types ¶
type Choice ¶
type Choice struct { Weight int Item interface{} }
A Choice contains a generic item and a weight controlling the frequency with which it will be selected.
func WeightedChoice ¶
WeightedChoice used weighted random selection to return one of the supplied choices. Weights of 0 are never selected. All other weight values are relative. E.g. if you have two choices both weighted 3, they will be returned equally often; and each will be returned 3 times as often as a choice weighted 1.
type Config ¶
type Config struct { // Quiet suppresses informational messages during profiling. Quiet bool // CPUProfile controls if cpu profiling will be enabled. // It defaults to false. CPUProfile bool // MemProfile controls if memory profiling will be enabled. // It defaults to false. MemProfile bool // BlockProfile controls if block (contention) profiling will // be enabled. // It defaults to false. BlockProfile bool // ProfilePath controls the base path where various profiling // files are written. If blank, the base path will be generated // by ioutil.TempDir. ProfilePath string // NoShutdownHook controls whether the profiling package should // hook SIGINT to write profiles cleanly. // Programs with more sophisticated signal handling should set // this to true and ensure the Stop() function returned from Start() // is called during shutdown. NoShutdownHook bool }
Config controls the operation of the profile package.