Documentation ¶
Overview ¶
Package db implements MongoDB database access methods.
Index ¶
- Variables
- func C(ctx context.Context, name string) (*mgo.Collection, error)
- func CheckID(s string) (bson.ObjectId, error)
- func Coll(s *mgo.Session, name string) (*mgo.Collection, error)
- func CtxSession(ctx context.Context) (*mgo.Session, error)
- func LockURL(s *mgo.Session) error
- func MongoCredential(cfg *conf.MongoCfg) error
- func NewContext(ctx context.Context, s *mgo.Session) context.Context
- func NewCtxSession(ctx context.Context, c *conf.Config, primary bool) (context.Context, *mgo.Session, error)
- func NewSession(c *conf.Conn, primary bool) (*mgo.Session, error)
- func UnlockURL(s *mgo.Session) error
- type Item
- type ItemURL
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Logger is a logger for error messages Logger = log.New(os.Stderr, "LOGGER [db]: ", log.Ldate|log.Ltime|log.Lshortfile) // Colls is a map of db collections names. // Keys can be used as aliases, values are real collection names. Colls = map[string]string{ "urls": "urls", "tracks": "tracks", "locks": "locks", "users": "users", "tests": "tests", } )
Functions ¶
func CtxSession ¶
CtxSession finds and returns MongoDB session from the Context.
func LockURL ¶
func LockURL(s *mgo.Session) error
LockURL locks short URL creation actions. It is useful for distributed usage, database is used for consistency short URLs values.
func MongoCredential ¶
MongoCredential initializes MongoDB credentials.
func NewContext ¶
NewContext returns a new Context carrying MongoDB session.
func NewCtxSession ¶
func NewCtxSession(ctx context.Context, c *conf.Config, primary bool) (context.Context, *mgo.Session, error)
NewCtxSession creates new database session and saves it to the context.
func NewSession ¶
NewSession returns new MongoDB session based on Conn data.
Types ¶
Click to show internal directories.
Click to hide internal directories.