Documentation ¶
Index ¶
- Constants
- Variables
- func Close()
- func Connect(servers string, database string, readPreference int, writeConcern *mgo.Safe)
- func GetObjectIdFromString(inputId string) (bson.ObjectId, error)
- func GetStringFromObjectId(input bson.ObjectId) string
- func Limit(r *http.Request) int
- func NoResult(input error) (bool, error)
- func Sort(r *http.Request) []string
Constants ¶
const ( ID_LENGTH = 24 LIMIT_DEFAULT_VALUE = 5 LIMIT_RETURN_ALL = 0 SORT_DEFAULT = "_id" )
Variables ¶
Functions ¶
func Connect ¶
CONNECT TO DB AND SETUP WRITE CONCERN AND READ PREFERENCE servers is string of at least one server to connect to ("localhost:27017/") and should be many hosts if using a replica set database is the name of your database to connect to readPreference is an mgo consistency constant (Eventual, Monotonic, Strong) writeConcern is an mgo *Safe type saves the connected session pool to a global variable.
func GetObjectIdFromString ¶
CONVERT A STRING INTO AN OBJECT ID validates the input string first and returns an error if input is not a valid string to convert in: objectId as a string out: mongo objectId and error if the input is not valid
func GetStringFromObjectId ¶
CONVERT AN OBJECT ID INTO A STRING in: mongo objectId out: string exactly 24 characters long and hexidecimal
func Limit ¶
GET A LIMIT FOR NUMBER FOR RESULTS TO RETURN FROM GET VARIABLE return the limit as an integer to use in db query 5 is the default if the limit form value is not understood a limit of 0 (zero) actually returns all results, not none gets the limit value from an http GET form value i.e. example.com?limit=10
func Sort ¶
GET A FIELD TO SORT FIND RESULTS BY FROM GET VARIABLE you can sort by one or many fields, each field name separated by a comma without whitespace you can prepend a (-) minus sign to sort in decending order example.log/?sort=birthday,-username make sure to use the value this function returns as sortOrder... (note three periods) in mgo Sort() this way mgo will apply all sorts to your query
Types ¶
This section is empty.