gormext

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: 22 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 Config

type Config struct {
	AutoMigrate bool   `json:"automigrate" yaml:"automigrate"`
	DBType      string `json:"dbType" yaml:"dbType"`
	URL         string `json:"url" yaml:"url"`
}

Config defined GORM Config

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 GORM

type GORM struct {
	DB  *gorm.DB
	API *API
	// contains filtered or unexported fields
}

GORM Type Defined

func New

func New() *GORM

New New mongo instance Export Session, API and AutoHook

func (*GORM) Conf

func (e *GORM) Conf(conf *Config) *GORM

Conf set e conf

func (*GORM) Docs

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

Docs defined Docs for bulrush

func (*GORM) Init

func (e *GORM) Init(init func(*GORM)) *GORM

Init e

func (*GORM) Model

func (e *GORM) Model(name string) *gorm.DB

Model return instance

func (*GORM) Plugin

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

Plugin defined plugin for bulrush

func (*GORM) Profile

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

Profile model profile

func (*GORM) Register

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

Register model should provide name and reflector paramters

func (*GORM) Var

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

Var return Var reflect from reflector entity

func (*GORM) Vars

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

Vars return array of Var

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 Model

type Model struct {
	ID        uint       `gorm:"comment:'模型ID';primary_key"`
	CreatedAt *time.Time `gorm:"comment:'创建时间'"`
	UpdatedAt *time.Time `gorm:"comment:'更新时间'"`
	DeletedAt *time.Time `sql:"index" gorm:"comment:'删除时间'"`
}

Model base model definition, including fields `ID`, `CreatedAt`, `UpdatedAt`, `DeletedAt`, which could be embedded in your models

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 Profile

type Profile struct {
	DB        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"`
		Select  string `form:"select" json:"select" xml:"select"`
		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{}
	SQL     string
	Select  string
	Preload []string
	Order   string
	Page    int
	Size    int
	Range   string
}

Query defined query std

func NewQuery

func NewQuery() *Query

NewQuery defined new query

func (*Query) Build

func (q *Query) Build(pre 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) BuildRelated

func (q *Query) BuildRelated()

BuildRelated defined related sql for preLoad

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