Documentation ¶
Overview ¶
Package util provides commonly used utility functions.
Index ¶
- Constants
- func CreateConnectionAddrs(host, port string) []string
- func FormatDate(v string) (interface{}, error)
- func GetFieldsFromFile(path string) ([]string, error)
- func IsFalsy(val interface{}) bool
- func IsTruthy(val interface{}) bool
- func MaxInt(a, b int) int
- func ParseConnectionString(connString string) ([]string, string)
- func SliceContains(slice, elt interface{}) bool
- func SliceCount(slice, elt interface{}) int
- func SplitAndValidateNamespace(namespace string) (string, string, error)
- func StringSliceContains(slice []string, str string) bool
- func ToFloat64(number interface{}) (float64, error)
- func ToInt(number interface{}) (int, error)
- func ToUInt32(number interface{}) (uint32, error)
- func ToUniversalPath(path string) string
- func ValidateCollectionGrammar(collection string) error
- func ValidateCollectionName(collection string) error
- func ValidateDBName(database string) error
- func ValidateFullNamespace(namespace string) error
Constants ¶
const ( ExitError int = 1 ExitClean int = 0 ExitBadOptions int = 3 ExitKill int = 4 )
const ( InvalidDBChars = "/\\. \"\x00$" InvalidCollectionChars = "$\x00" DefaultHost = "localhost" DefaultPort = "27017" )
Variables ¶
This section is empty.
Functions ¶
func CreateConnectionAddrs ¶
Split the host string into the individual nodes to connect to, appending the port if necessary.
func FormatDate ¶
func GetFieldsFromFile ¶
GetFieldsFromFile fetches the first line from the contents of the file at "path"
func IsFalsy ¶
func IsFalsy(val interface{}) bool
IsFalsy returns true for values the server will interpret as "false". False values include numbers == 0, false, and nil
func IsTruthy ¶
func IsTruthy(val interface{}) bool
IsTruthy returns true for values the server will interpret as "true". True values include {}, [], "", true, and any numbers != 0
func ParseConnectionString ¶
Extract the replica set name and the list of hosts from the connection string
func SliceContains ¶
func SliceContains(slice, elt interface{}) bool
generic function that returns true if elt is in slice. panics if slice is not of Kind reflect.Slice
func SliceCount ¶
func SliceCount(slice, elt interface{}) int
generic function that returns number of instances of 'elt' in 'slice'. panics if slice is not of Kind reflect.Slice
func SplitAndValidateNamespace ¶
SplitNamespace splits a namespace path into a database and collection, returned in that order. An error is returned if the namespace is invalid.
func StringSliceContains ¶
func ToInt ¶
ToInt is a function for converting any numeric type into an int. This can easily result in a loss of information due to truncation of floats.
func ToUInt32 ¶
ToUInt32 is a function for converting any numeric type into a uint32. This can easily result in a loss of information due to truncation, so be careful.
func ToUniversalPath ¶
ToUniversalPath returns the result of replacing each slash ('/') character in "path" with an OS-sepcific separator character. Multiple slashes are replaced by multiple separators
func ValidateCollectionGrammar ¶
ValidateCollectionGrammar validates the collection for character and length errors without erroring on system collections. For validation of functionality that manipulates system collections.
func ValidateCollectionName ¶
ValidateCollectionName validates that a string is a valid name for a mongodb collection. An error is returned if it is not valid.
func ValidateDBName ¶
ValidateDBName validates that a string is a valid name for a mongodb database. An error is returned if it is not valid.
func ValidateFullNamespace ¶
ValidateFullNamespace validates a full mongodb namespace (database + collection), returning an error if it is invalid.
Types ¶
This section is empty.