controller

package
v0.0.62 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TOKEN         = "token"
	ACCESS_TOKEN  = "access_token"
	REFRESH_TOKEN = "refresh_token"
	NAME          = "name"
	ID            = "id"
	SESSION_ID    = "session_id"
)
View Source
const (
	MAX_AVATAR_SIZE = 1024 * 1024 * 2   // 2M
	MAX_IMPORT_SIZE = 5 * 1024 * 1024   // 5M
	MAX_UPLOAD_SIZE = 1024 * 1024 * 100 // 100M
)
View Source
const (
	QUERY_ID          = types.QUERY_ID
	QUERY_PAGE        = types.QUERY_PAGE
	QUERY_SIZE        = types.QUERY_SIZE
	QUERY_LIMIT       = types.QUERY_LIMIT
	QUERY_EXPAND      = types.QUERY_EXPAND
	QUERY_DEPTH       = types.QUERY_DEPTH
	QUERY_OR          = types.QUERY_OR
	QUERY_FUZZY       = types.QUERY_FUZZY
	QUERY_SORTBY      = types.QUERY_SORTBY
	QUERY_COLUMN_NAME = types.QUERY_COLUMN_NAME
	QUERY_START_TIME  = types.QUERY_START_TIME
	QUERY_END_TIME    = types.QUERY_END_TIME
	QUERY_NOCACHE     = types.QUERY_NOCACHE
	QUERY_NOTOTAL     = types.QUERY_NOTOTAL
	QUERY_TYPE        = types.QUERY_TYPE
	QUERY_FILENAME    = types.QUERY_FILENAME
	QUERY_INDEX       = types.QUERY_INDEX
	QUERY_SELECT      = types.QUERY_SELECT

	PARAM_ID   = types.PARAM_ID
	PARAM_FILE = types.PARAM_FILE

	CTX_USERNAME = types.CTX_USERNAME

	VALUE_ALL = types.VALUE_ALL
)

Variables

View Source
var Column = new(column)
View Source
var PAGE_ID = time.Now().Unix()
View Source
var Portal = new(portal)
View Source
var Probe = new(probe)
View Source
var Upload = new(upload)
View Source
var User = new(user)

Functions

func Create

func Create[M types.Model](c *gin.Context)

Create is a generic function to product gin handler to create one resource. The resource type depends on the type of interface types.Model.

func CreateFactory

func CreateFactory[M types.Model](cfg ...*types.ControllerConfig[M]) gin.HandlerFunc

CreateFactory is a factory function to product gin handler to create one resource.

func Delete

func Delete[M types.Model](c *gin.Context)

Delete is a generic function to product gin handler to delete one or multiple resources. The resource type depends on the type of interface types.Model.

Resource id must be specify and all resources that id matched will be deleted in database.

Delete one resource: - specify resource `id` in "router parameter", eg: localhost:9000/api/myresource/myid - specify resource `id` in "query parameter", eg: localhost:9000/api/myresource?id=myid

Delete multiple resources: - specify resource `id` slice in "http body data".

func DeleteFactory

func DeleteFactory[M types.Model](cfg ...*types.ControllerConfig[M]) gin.HandlerFunc

DeleteFactory is a factory function to product gin handler to delete one or multiple resources.

func Export

func Export[M types.Model](c *gin.Context)

Export is a generic function to product gin handler to export resources to frontend. The resource type deponds on the type of interface types.Model.

If you want make a structure field as query parameter, you should add a "schema" tag for it. for example: schema:"name"

TODO:combine query parameter 'page' and 'size' into decoded types.Model FIX: retrieve records recursive (current not support in gorm.) https://stackoverflow.com/questions/69395891/get-recursive-field-values-in-gorm DB.Preload("Category.Category.Category").Find(&Category) its works for me.

Query parameters:

  • All feilds of types.Model's underlying structure but excluding some special fields, such as "password", field value too large, json tag is "-", etc.
  • `_expand`: strings (multiple items separated by ","). The responsed data to frontend will expanded(retrieve data from external table accoding to foreign key) For examples: /department/myid?_expand=children /department/myid?_expand=children,parent
  • `_depth`: strings or interger. How depth to retrieve records from datab recursivly, default to 1, value scope is [1,99]. For examples: /department/myid?_expand=children&_depth=3 /department/myid?_expand=children,parent&_depth=10
  • `_fuzzy`: bool fuzzy match records in database, default to fase. For examples: /department/myid?_fuzzy=true

func ExportFactory

func ExportFactory[M types.Model](cfg ...*types.ControllerConfig[M]) gin.HandlerFunc

ExportFactory is a factory function to export resources to frontend.

func Get

func Get[M types.Model](c *gin.Context)

Get is a generic function to product gin handler to list resource in backend. The resource type deponds on the type of interface types.Model.

Query parameters:

  • `_expand`: strings (multiple items separated by ","). The responsed data to frontend will expanded(retrieve data from external table accoding to foreign key) For examples: /department/myid?_expand=children /department/myid?_expand=children,parent
  • `_depth`: strings or interger. How depth to retrieve records from datab recursivly, default to 1, value scope is [1,99]. For examples: /department/myid?_expand=children&_depth=3 /department/myid?_expand=children,parent&_depth=10

Route parameters: - id: string or integer.

func GetFactory

func GetFactory[M types.Model](cfg ...*types.ControllerConfig[M]) gin.HandlerFunc

GetFactory is a factory function to product gin handler to list resource in backend.

func Import

func Import[M types.Model](c *gin.Context)

Import

func ImportFactory

func ImportFactory[M types.Model](cfg ...*types.ControllerConfig[M]) gin.HandlerFunc

ImportFactory

func List

func List[M types.Model](c *gin.Context)

List is a generic function to product gin handler to list resources in backend. The resource type deponds on the type of interface types.Model.

If you want make a structure field as query parameter, you should add a "schema" tag for it. for example: schema:"name"

TODO:combine query parameter 'page' and 'size' into decoded types.Model FIX: retrieve records recursive (current not support in gorm.) https://stackoverflow.com/questions/69395891/get-recursive-field-values-in-gorm DB.Preload("Category.Category.Category").Find(&Category) its works for me.

Query parameters:

  • All feilds of types.Model's underlying structure but excluding some special fields, such as "password", field value too large, json tag is "-", etc.
  • `_expand`: strings (multiple items separated by ","). The responsed data to frontend will expanded(retrieve data from external table accoding to foreign key) For examples: /department/myid?_expand=children /department/myid?_expand=children,parent
  • `_depth`: strings or interger. How depth to retrieve records from datab recursivly, default to 1, value scope is [1,99]. For examples: /department/myid?_expand=children&_depth=3 /department/myid?_expand=children,parent&_depth=10
  • `_fuzzy`: bool fuzzy match records in database, default to fase. For examples: /department/myid?_fuzzy=true

func ListFactory

func ListFactory[M types.Model](cfg ...*types.ControllerConfig[M]) gin.HandlerFunc

ListFactory is a factory function to product gin handler to list resources in backend.

func PageID

func PageID(c *gin.Context)

func Update

func Update[M types.Model](c *gin.Context)

Update is a generic function to product gin handler to update one resource. The resource type depends on the type of interface types.Model.

Update will update one resource and resource "ID" must be specified, which can be specify in "router parameter `id`" or "http body data".

"router parameter `id`" has more priority than "http body data". It will skip decode id from "http body data" if "router parameter `id`" not empty.

func UpdateFactory

func UpdateFactory[M types.Model](cfg ...*types.ControllerConfig[M]) gin.HandlerFunc

UpdateFactory is a factory function to product gin handler to update one resource.

func UpdatePartial

func UpdatePartial[M types.Model](c *gin.Context)

UpdatePartial is a generic function to product gin handler to partial update one resource. The resource type depends on the type of interface types.Model.

resource id must be specified. - specified in "query parameter `id`". - specified in "router parameter `id`".

which one or multiple resources desired modify. - specified in "query parameter". - specified in "http body data".

func UpdatePartialFactory

func UpdatePartialFactory[M types.Model](cfg ...*types.ControllerConfig[M]) gin.HandlerFunc

UpdatePartialFactory is a factory function to product gin handler to partial update one resource.

Types

This section is empty.

Jump to

Keyboard shortcuts

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