Documentation ¶
Overview ¶
Package mongo provides handful wrapper to access and/or modify the mongo database.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DbClient ¶
type DbClient struct {
// contains filtered or unexported fields
}
func (*DbClient) Open ¶
func (c *DbClient) Open(db, collection string) (*mgo.Collection, *DbSession)
func (*DbClient) OpenWithLongTimeout ¶
func (c *DbClient) OpenWithLongTimeout(db, collection string) (*mgo.Collection, *DbSession)
type DbSession ¶
func Open ¶
func Open(db, c string) (*mgo.Collection, *DbSession)
Open returns a mgo collection and session.
func OpenWithLongTimeout ¶
func OpenWithLongTimeout(db, c string) (*mgo.Collection, *DbSession)
Open returns a mgo collection and session with long session timeout. It's useful for task specific query, which may need dozens of time to complete. NOTE: It's risky to use such session in server, where may lead to infinite no response status.
type Hint ¶
type Hint struct { // ServerName is used to specify the server. ServerName string `json:"server_name"` // Database and Collection is used to determine the whether this server // should be used. It follows the rule to choose the server: // 1. Both database and collection argument are perfectly matched. // 2. If no such match, the LAST hint matching the db. // 3. If no such match(no such database in the config), the LAST hint matching the collection. // 4. Choose the first server given in Servers section. Database string `json:"database"` Collection string `json:"collection"` }
type LocalRepos ¶
LocalRepos is a Key/Value map that cached the data from a particular mongodb to local memory, and keep refreshing data in certian intervals. It's useful for small collection with high read I/O.
func NewLocalRepos ¶
func NewLocalRepos(db, col string, entryTmpl Hashable, opts ...ReposOption) *LocalRepos
func (*LocalRepos) AllItems ¶
func (r *LocalRepos) AllItems() []*ReposKVEntry
func (*LocalRepos) AllKeys ¶
func (r *LocalRepos) AllKeys() []string
func (*LocalRepos) AllValues ¶
func (r *LocalRepos) AllValues() []Hashable
func (*LocalRepos) Close ¶
func (r *LocalRepos) Close()
func (*LocalRepos) Get ¶
func (r *LocalRepos) Get(id string) Hashable
func (*LocalRepos) Init ¶
func (r *LocalRepos) Init()
func (*LocalRepos) Len ¶
func (r *LocalRepos) Len() int
type ReposKVEntry ¶
type ReposOption ¶
type ReposOption func(*LocalRepos)
func WithClient ¶
func WithClient(client *DbClient) ReposOption
func WithProjection ¶
func WithProjection(project bson.M) ReposOption
func WithQuery ¶
func WithQuery(query bson.M) ReposOption
func WithRefreshInterval ¶
func WithRefreshInterval(dur time.Duration) ReposOption
type Router ¶
type Router struct { Servers []*Server `json:"servers"` Hints []*Hint `json:"hints"` HintMap map[string]*Server `json:"-"` }
Router is a smart proxy to open a proper mongodb client determined by the required database and/or collection combination.
func LoadJsonFileRouter ¶
func (*Router) DetermineServer ¶
DetermineServer returns a matching server entry.