Skip to content

To establish a database session(mds) to request another gin-middleware

License

Notifications You must be signed in to change notification settings

dogenzaka/mdsession

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

To establish a database session(mds) to request another gin-middleware

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages