mongo

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: May 25, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

README

MongoDB

package main

import (
    "context"

    "github.com/joshqu1985/fireman/configor"
    "github.com/joshqu1985/fireman/store/mongo"
)

type Config struct {
    Mongo    mongo.Config
}

var (
    Conf Config
)

func init() {
    if err := configor.Load("./configs/conf.toml", &Conf); err != nil {
        panic(err)
    }
}

type Summary struct {
    ObjectId        string `json:"object_id" bson:"object_id"`
    CommsCount      int    `json:"comms_count" bson:"comms_count"`
    CommsFirstCount int    `json:"comms_first_count" bson:"comms_first_count"`
    LikesCount      int    `json:"likes_count" bson:"likes_count"`
    RepostsCount    int    `json:"reposts_count" bson:"reposts_count"`
    IsLiking        bool   `json:"is_liking" bson:"is_liking,omitempty"`
}

func main() {
    pool := mongo.NewPool(Conf.Mongo)

    item := &Summary{}
    handle := func(c *mongo.Collection) error {
        return c.Find(mongo.M{"object_id": objectId}).One(item)
    }
    err := pool.DB("BoardSummary").Doit(ctx, "summary", handle)

    fmt.Prinln(item, err)
}
#conf.toml
[mongo]
    host     = "127.0.0.1:27017"
    auth     = "" # "test:BwUSdSQxtUx@"
    opts     = "minPoolSize=0&maxIdleTimeMS=3000"
    database = ["BoardComment", "BoardLike", "BoardSummary"]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection

type Collection = mgo.Collection

type Config

type Config struct {
	Host     string
	Auth     string
	Opts     string
	Database []string
}

type M

type M = bson.M

type Pool

type Pool struct {
	Sessions map[string]*mgo.Session
}

func NewPool

func NewPool(conf Config) *Pool

func (*Pool) DB

func (p *Pool) DB(name string) *dbInstance

Jump to

Keyboard shortcuts

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