ginrester

package module
v0.0.0-...-18a2c96 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2019 License: MIT Imports: 9 Imported by: 0

README

GinRester

a restful plugin with gin+gorm, GinRester is an easy way to build api faster.

Find example, and free to use.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Db *gorm.DB
View Source
var PerPage = 20

Functions

func BuildRoute

func BuildRoute(controller ControllerInterface) (path, resourceName, routeId string)

func CheckUpdateCondition

func CheckUpdateCondition(m ResourceInterface, condition map[string]interface{})

func CreateRoutes

func CreateRoutes(group *gin.RouterGroup, controller ControllerInterface, actions ...string)

func ExsitAndFirst

func ExsitAndFirst(res ResourceInterface)

func FindListByMap

func FindListByMap(res interface{}, where map[string]interface{}, order string, page int, perPage int)

func GetRouteID

func GetRouteID(controller ControllerInterface) (routeId string)

func MergeUrlCondition

func MergeUrlCondition(condition map[string]interface{}, query url.Values, obj interface{})

func ReturnSuccess

func ReturnSuccess(c *gin.Context, code int, data interface{})

func SetForbidUpdateFields

func SetForbidUpdateFields(fs ...string) []string

Types

type BaseController

type BaseController struct{}

func (*BaseController) GetModel

func (this *BaseController) GetModel() ResourceInterface

func (BaseController) GetModelSlice

func (this BaseController) GetModelSlice() interface{}

func (BaseController) Rester

func (this BaseController) Rester()

type Controller

type Controller struct {
	ParentController ControllerInterface
	Rester           ControllerInterface
	RestModel        func() ResourceInterface
	RestModelSlice   func() interface{} //https://golang.org/doc/faq#convert_slice_of_interface
	*BaseController
}

func (*Controller) Create

func (action *Controller) Create(c *gin.Context)

func (*Controller) Delete

func (action *Controller) Delete(c *gin.Context)

func (*Controller) Info

func (action *Controller) Info(c *gin.Context)

func (*Controller) Init

func (action *Controller) Init(r ControllerInterface)

func (*Controller) IsRestRoutePk

func (action *Controller) IsRestRoutePk() bool

func (*Controller) List

func (action *Controller) List(c *gin.Context)

func (*Controller) ParentNode

func (action *Controller) ParentNode() ControllerInterface

func (*Controller) RouteName

func (action *Controller) RouteName() string

func (*Controller) Update

func (action *Controller) Update(c *gin.Context)

type ControllerInterface

type ControllerInterface interface {
	Update(c *gin.Context)
	Create(c *gin.Context)
	Info(c *gin.Context)
	List(c *gin.Context)
	Delete(c *gin.Context)
	IsRestRoutePk() bool //false id
	RouteName() string   //rewrite resource name in route url
	ParentNode() ControllerInterface

	Init(r ControllerInterface)
	GetModel() ResourceInterface
	GetModelSlice() interface{}
	// contains filtered or unexported methods
}

type ForbidUpdateResource

type ForbidUpdateResource struct{}

func (ForbidUpdateResource) ForbidUpdate

func (bf ForbidUpdateResource) ForbidUpdate() bool

type JsonSuccess

type JsonSuccess struct {
	Data interface{} `json:"data"`
}

type Model

type Model struct {
	ID        int        `gorm:"primary_key" json:"id"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `json:"deleted_at"`
}

func (Model) ForbidUpdateFields

func (bf Model) ForbidUpdateFields() []string

func (Model) InfoFields

func (bf Model) InfoFields() []string

func (Model) ListFields

func (bf Model) ListFields() []string

type ResourceInterface

type ResourceInterface interface {
	ListFields() []string
	InfoFields() []string
	ForbidUpdateFields() []string
}

func DeleteByID

func DeleteByID(res ResourceInterface, id int) ResourceInterface

func FindOneByID

func FindOneByID(res ResourceInterface, id int) ResourceInterface

func FindOneByMap

func FindOneByMap(res ResourceInterface, where map[string]interface{}) ResourceInterface

func UpdateByID

func UpdateByID(id int, res ResourceInterface) ResourceInterface

func UpdateWhere

func UpdateWhere(where map[string]interface{}, res ResourceInterface) ResourceInterface

Jump to

Keyboard shortcuts

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