mgoext

package
v0.0.0-...-5d03f69 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2019 License: MIT Imports: 20 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FailureHandler = func(c *gin.Context) {
	c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
		"message": "Access Denied, you don't have permission",
	})
}

FailureHandler handlerss

Functions

func GenDoc

func GenDoc(profile *Profile, routePrefixs *RoutePrefixs, apis ...string) *[]Doc

GenDoc defined doc

Types

type API

type API struct {
	Opts *Opts
	// contains filtered or unexported fields
}

API type defined

func (*API) ALL

func (ai *API) ALL(r *gin.RouterGroup, name string, handlers ...gin.HandlerFunc) *Hook

ALL hook auto generate api

func (*API) Create

func (ai *API) Create(r *gin.RouterGroup, name string, handlers ...gin.HandlerFunc) *Hook

Create hook auto generate api

func (*API) Delete

func (ai *API) Delete(r *gin.RouterGroup, name string, handlers ...gin.HandlerFunc) *Hook

Delete hook auto generate api

func (*API) Feature

func (ai *API) Feature(name string) *API

Feature defined feature api

func (*API) FeatureWithOpts

func (ai *API) FeatureWithOpts(opts *Opts) *API

FeatureWithOpts defined feature api with opts

func (*API) List

func (ai *API) List(r *gin.RouterGroup, name string, handlers ...gin.HandlerFunc) *Hook

List hook auto generate api

func (*API) One

func (ai *API) One(r *gin.RouterGroup, name string, handlers ...gin.HandlerFunc) *Hook

One hook auto generate api

func (*API) Update

func (ai *API) Update(r *gin.RouterGroup, name string, handlers ...gin.HandlerFunc) *Hook

Update hook auto generate api

type CreateHook

type CreateHook struct {
	Pre  func(*gin.Context)
	Post func(*gin.Context)
	Auth func(*gin.Context) bool
	Form func(form) form
}

CreateHook defined create hook opts

type DeleteHook

type DeleteHook struct {
	Pre  func(*gin.Context)
	Post func(*gin.Context)
	Auth func(*gin.Context) bool
	Form func(form) form
	Cond func(map[string]interface{}, *gin.Context, struct{ Name string }) map[string]interface{}
}

DeleteHook defined delete hook opts

type Doc

type Doc struct {
	Type       string    `json:"type" yaml:"type"`
	URL        string    `json:"url" yaml:"url"`
	Title      string    `json:"title" yaml:"title"`
	Name       string    `json:"name" yaml:"name"`
	Group      string    `json:"group" yaml:"group"`
	Desc       string    `json:"description" yaml:"description"`
	Version    string    `json:"version" yaml:"version"`
	GroupTitle string    `json:"groupTitle" yaml:"groupTitle"`
	Parameter  Parameter `json:"parameter" yaml:"parameter"`
}

Doc defined model api doc

type Example

type Example struct {
	Title   string `json:"title" yaml:"title"`
	Content string `json:"content" yaml:"content"`
	Type    string `json:"type" yaml:"type"`
}

Example defined model api doc

type Fields

type Fields struct {
	FieldsParameter []FieldsParameter `json:"Parameter" yaml:"Parameter"`
}

Fields defined model api doc

type FieldsParameter

type FieldsParameter struct {
	Tags     reflect.StructTag `json:"-" yaml:"-"`
	Group    string            `json:"group" yaml:"group"`
	Type     string            `json:"type" yaml:"type"`
	Optional bool              `json:"optional" yaml:"optional"`
	Field    string            `json:"field" yaml:"field"`
	Desc     string            `json:"description" yaml:"description"`
}

FieldsParameter defined model api doc

type Hook

type Hook struct {
	// contains filtered or unexported fields
}

Hook for API

func (*Hook) Auth

func (h *Hook) Auth(auth func(*gin.Context) bool) *Hook

Auth defined pre handler

func (*Hook) Post

func (h *Hook) Post(post func(*gin.Context)) *Hook

Post defined pre handler

func (*Hook) Pre

func (h *Hook) Pre(pre func(*gin.Context)) *Hook

Pre defined pre handler

func (*Hook) RouteHooks

func (h *Hook) RouteHooks(hooks *RouteHooks) *Hook

RouteHooks defined RouteHooks

type ListHook

type ListHook struct {
	Pre  func(*gin.Context)
	Post func(*gin.Context)
	Auth func(*gin.Context) bool
	Cond func(map[string]interface{}, *gin.Context, struct{ Name string }) map[string]interface{}
}

ListHook defined list hook opts

type M

type M map[string]interface{}

M defined alia map[string]interface{}

type Model

type Model struct {
	ID        bson.ObjectId `bson:"_id,omitempty" br:"comment:'模型ID'"`
	CreatedAt *time.Time    `bson:"_created" br:"comment:'创建时间'"`
	UpdatedAt *time.Time    `bson:"_updated" br:"comment:'修改时间'"`
	DeletedAt *time.Time    `bson:"_deleted" br:"comment:'删除时间'"`
}

Model common fields

type Mongo

type Mongo struct {
	Session *mgo.Session
	API     *API
	// contains filtered or unexported fields
}

Mongo Type Defined

func New

func New() *Mongo

New New mongo instance Export Session, API and AutoHook

func (*Mongo) Conf

func (e *Mongo) Conf(conf *mgo.DialInfo) *Mongo

Conf defined conf

func (*Mongo) Docs

func (e *Mongo) Docs() *[]Doc

Docs defined Docs for bulrush

func (*Mongo) Init

func (e *Mongo) Init(init func(*Mongo)) *Mongo

Init mgo

func (*Mongo) Model

func (e *Mongo) Model(name string) *mgo.Collection

Model return instance throw error if not exists these model

func (*Mongo) Plugin

func (e *Mongo) Plugin(r *gin.RouterGroup) *Mongo

Plugin defined plugin for bulrush

func (*Mongo) Profile

func (e *Mongo) Profile(name string) *Profile

Profile model profile

func (*Mongo) Register

func (e *Mongo) Register(profile *Profile) *Mongo

Register model should provide name and reflector paramters

func (*Mongo) Var

func (e *Mongo) Var(name string) interface{}

Var return Var reflect from reflector entity

func (*Mongo) Vars

func (e *Mongo) Vars(name string) interface{}

Vars return array of Var

type OneHook

type OneHook struct {
	Pre  func(*gin.Context)
	Post func(*gin.Context)
	Auth func(c *gin.Context) bool
	Cond func(map[string]interface{}, *gin.Context, struct{ Name string }) map[string]interface{}
}

OneHook defined one hook opts

type Opts

type Opts struct {
	Prefix        string
	FeaturePrefix string
	RoutePrefixs  *RoutePrefixs
	RouteHooks    *RouteHooks
}

Opts defined api params

type Parameter

type Parameter struct {
	Fields   Fields    `json:"fields" yaml:"fields"`
	Examples []Example `json:"examples" yaml:"examples"`
}

Parameter defined model api doc

type PreloadInfo

type PreloadInfo struct {
	BsonName string
	IsArray  bool
	Coll     string
	Local    string
	Foreign  string
	Up       string
}

PreloadInfo defined preload unit

type Profile

type Profile struct {
	DB         string
	Collection string
	Name       string
	Reflector  interface{}
	AutoHook   bool
	Opts       *Opts
	// contains filtered or unexported fields
}

Profile defined model profile

type Query

type Query struct {
	Query struct {
		Cond     string `form:"cond" json:"cond" xml:"cond"`
		Project  string `form:"project" json:"project" xml:"project"`
		UProject string `form:"uproject" json:"uproject" xml:"uproject"`
		Preload  string `form:"preload" json:"preload" xml:"preload"`
		Order    string `form:"order" json:"order" xml:"order"`
		Page     int    `form:"page" json:"page" xml:"page"`
		Size     int    `form:"size" json:"size" xml:"size"`
		Range    string `form:"range" json:"range" xml:"range"`
	}

	Cond     map[string]interface{}
	Pipe     []M
	Project  map[string]interface{}
	UProject map[string]interface{}
	Preload  string
	Order    map[string]interface{}
	Page     int
	Size     int
	Range    string
	// contains filtered or unexported fields
}

Query defined query std

func NewQuery

func NewQuery() *Query

NewQuery defined return query with default

func (*Query) Build

func (q *Query) Build(cond map[string]interface{}) error

Build defined all build

func (*Query) BuildCond

func (q *Query) BuildCond(cond map[string]interface{}) error

BuildCond defined select sql

func (*Query) BuildOrder

func (q *Query) BuildOrder()

BuildOrder defined order sql

func (*Query) BuildPipe

func (q *Query) BuildPipe() error

BuildPipe defined pipe array

func (*Query) BuildProject

func (q *Query) BuildProject()

BuildProject dfined build select fields

func (*Query) BuildRelated

func (q *Query) BuildRelated() []M

BuildRelated defined related sql for preLoad

func (*Query) BuildUProject

func (q *Query) BuildUProject()

BuildUProject dfined build select fields

type RouteHooks

type RouteHooks struct {
	One    *OneHook
	List   *ListHook
	Create *CreateHook
	Update *UpdateHook
	Delete *DeleteHook
}

RouteHooks defined route hooks

type RoutePrefixs

type RoutePrefixs struct {
	One    func(string) string
	List   func(string) string
	Create func(string) string
	Update func(string) string
	Delete func(string) string
	// contains filtered or unexported fields
}

RoutePrefixs defined route prefixs

type UpdateHook

type UpdateHook struct {
	Pre  func(*gin.Context)
	Post func(*gin.Context)
	Auth func(*gin.Context) bool
	Form func(form) form
	Cond func(map[string]interface{}, *gin.Context, struct{ Name string }) map[string]interface{}
}

UpdateHook defined create hook opts

Jump to

Keyboard shortcuts

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