Documentation ¶
Overview ¶
Package gimo is a Go library to build CRUD APIs with Gin and mgo.
Index ¶
Constants ¶
const ( // DefaultRequestCtxKey is the default Gin context key uder // which the parsed request body is stored. The request context // key can be customized with the "New"" function. DefaultRequestCtxKey = "request" // DefaultResponseCtxKey is the default Gin context key uder // which the response struct is stored. The response context key // can be customized with the "New"" function. DefaultResponseCtxKey = "response" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DocumentBase ¶
type DocumentBase struct {
ID string `json:"id" bson:"_id"`
}
func (*DocumentBase) GetID ¶
func (d *DocumentBase) GetID() string
func (*DocumentBase) SetID ¶
func (d *DocumentBase) SetID(id string)
type Library ¶
type Library struct { BaseGroup *gin.RouterGroup Session *mgo.Session RequestCtxKey string ResponseCtxKey string }
Library is Gimo's core instance. It contains settings that are common to all resources.
func Default ¶
func Default(baseGroup *gin.RouterGroup, dbInfo *mgo.DialInfo) *Library
Default returns a Library instance with default internal settings.
func New ¶
func New(baseGroup *gin.RouterGroup, dbInfo *mgo.DialInfo, requestCtxKey string, responseCtxKey string) *Library
New returns a Library instance.
type Resource ¶
type Resource struct { *Library Name string Group *gin.RouterGroup Doc Document }
Resource represents a single CRUD resource.
func (*Resource) Create ¶
func (r *Resource) Create(mw ...gin.HandlerFunc)
Create adds a Gin handler function that allows a client to create a new document in the mongoDB collection.
func (*Resource) Delete ¶
func (r *Resource) Delete(mw ...gin.HandlerFunc)
Delete adds a Gin handler function that allows a client to remove a document from the mongoDB collection.
func (*Resource) List ¶
func (r *Resource) List(mw ...gin.HandlerFunc)
List adds a Gin handler function that allows a client to get all documents from the mongoDB collection.
func (*Resource) Read ¶
func (r *Resource) Read(mw ...gin.HandlerFunc)
Read adds a Gin handler function that allows a client to get a single document from the mongoDB collection.
func (*Resource) Update ¶
func (r *Resource) Update(mw ...gin.HandlerFunc)
Update adds a Gin handler function that allows a client to update an existing document in the mongoDB collection.