util

package
v0.0.0-...-a15ebab Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2016 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package util provides commonly used utility functions.

Index

Constants

View Source
const (
	ExitError      int = 1
	ExitClean      int = 0
	ExitBadOptions int = 3
	ExitKill       int = 4
)
View Source
const (
	InvalidDBChars         = "/\\. \"\x00$"
	InvalidCollectionChars = "$\x00"
	DefaultHost            = "localhost"
	DefaultPort            = "27017"
)

Variables

View Source
var (
	ErrTerminated = errors.New("received termination signal")
)

Functions

func CreateConnectionAddrs

func CreateConnectionAddrs(host, port string) []string

Split the host string into the individual nodes to connect to, appending the port if necessary.

func FormatDate

func FormatDate(v string) (interface{}, error)

func GetFieldsFromFile

func GetFieldsFromFile(path string) ([]string, error)

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 MaxInt

func MaxInt(a, b int) int

Return the max of two ints

func ParseConnectionString

func ParseConnectionString(connString string) ([]string, string)

Extract the replica set name and the list of hosts from the connection string

func Pluralize

func Pluralize(amount int, singular, plural string) string

Pluralize takes an amount and two strings denoting the singular and plural noun the amount represents. If the amount is singular, the singular form is returned; otherwise plural is returned. E.g.

Pluralize(X, "mouse", "mice") -> 0 mice, 1 mouse, 2 mice, ...

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

func SplitAndValidateNamespace(namespace string) (string, string, error)

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 StringSliceContains(slice []string, str string) bool

func ToFloat64

func ToFloat64(number interface{}) (float64, error)

ToFloat64 is a function for converting any numeric type into a float64.

func ToInt

func ToInt(number interface{}) (int, error)

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

func ToUInt32(number interface{}) (uint32, error)

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

func ToUniversalPath(path string) string

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

func ValidateCollectionGrammar(collection string) error

ValidateCollectionGrammar validates the collection for character and length errors without erroring on system collections. For validation of functionality that manipulates system collections.

func ValidateCollectionName

func ValidateCollectionName(collection string) error

ValidateCollectionName validates that a string is a valid name for a mongodb collection. An error is returned if it is not valid.

func ValidateDBName

func ValidateDBName(database string) error

ValidateDBName validates that a string is a valid name for a mongodb database. An error is returned if it is not valid.

func ValidateFullNamespace

func ValidateFullNamespace(namespace string) error

ValidateFullNamespace validates a full mongodb namespace (database + collection), returning an error if it is invalid.

Types

This section is empty.

Jump to

Keyboard shortcuts

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