mongo

package
v0.0.0-...-6530dd9 Latest Latest
Warning

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

Go to latest
Published: May 30, 2017 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package mongo provides Datatables handlers for MongoDB.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateFilter

func CreateFilter(r types.Request) bson.M

CreateFilter creates a BSON query from a Datatables Request.

func ResponseData

func ResponseData(q Query) (data []types.Row, err error)

ResponseData returns the data for a given query that can be used in a Datatables Response.

Types

type Collection

type Collection interface {
	Count() (n int, err error)
	Find(query interface{}) Query
}

Collection interface contains the *mgo.Collection methods used.

type CollectionHandler

type CollectionHandler struct {
	Collection Collection
}

CollectionHandler provides a HTTP handler for a mgo collection.

Example
session, _ := mgo.Dial("mymongohost")
c := session.DB("mydb").C("mycollection")
http.Handle("/mycollection", NewCollectionHandler(c))
http.ListenAndServe(":8080", nil)
Output:

func NewCollectionHandler

func NewCollectionHandler(c *mgo.Collection) *CollectionHandler

NewCollectionHandler returns a CollectionHandler for the given collection.

func (*CollectionHandler) ServeHTTP

func (ch *CollectionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface

type Query

type Query interface {
	All(result interface{}) error
	Count() (n int, err error)
	Limit(n int) Query
	Skip(n int) Query
	Sort(fields ...string) Query
}

Query interface defines the *mgo.Query methods used.

func RangeQuery

func RangeQuery(in Query, r types.Request) (out Query)

RangeQuery sets range of items to return based on the Datatables Request.

func SortQuery

func SortQuery(in Query, r types.Request) (out Query)

SortQuery sets the queries sort options based on the Request.

Jump to

Keyboard shortcuts

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