Skip to content

Latest commit

 

History

History
88 lines (58 loc) · 1.37 KB

README.md

File metadata and controls

88 lines (58 loc) · 1.37 KB

mdsession During the development :)

What is mdsession?

Middleware which sets up an established database session according to a request at *gin.Context

Features

  • Support database
    • MongoDB
    • Redis
    • RethinkDB

Requirements

Test

Getgin started

TODO

Example

var option *Option = &mdsession.Option{
    Dn: DnName, // uniq datastore name
    Name: Name, // Key to the `*gin.Context`
    Make: true, // To connect every time

}

var options *Options = &mdsession.Options{
    Sets: []*Option{option},
}

g := gin.New()

// append gin middleware
g.Use(MiddlewareMongoDB(options))


g.GET("/test", func(c *gin.Context) {
    ret, err := c.Get(Name)
    s, ok := ret.(*mgo.Session)

    if ret != nil && err == nil && ok {
        c.String(200, "OK dbs: " + fmt.Sprint(s.DatabaseNames()))
    } else {
        c.String(500, "NG")
    }
})

Please read the test code.

Developer

Test

$ go get github.com/mattn/gom # package manager
$ make init
$ make test

Coverage

$ go get github.com/smartystreets/goconvey // Coverage library
$ make cover

License

MIT License