Documentation ¶
Index ¶
- Constants
- Variables
- func Create[M types.Model](c *gin.Context)
- func CreateFactory[M types.Model](cfg ...*types.ControllerConfig[M]) gin.HandlerFunc
- func Delete[M types.Model](c *gin.Context)
- func DeleteFactory[M types.Model](cfg ...*types.ControllerConfig[M]) gin.HandlerFunc
- func Export[M types.Model](c *gin.Context)
- func ExportFactory[M types.Model](cfg ...*types.ControllerConfig[M]) gin.HandlerFunc
- func Get[M types.Model](c *gin.Context)
- func GetFactory[M types.Model](cfg ...*types.ControllerConfig[M]) gin.HandlerFunc
- func Import[M types.Model](c *gin.Context)
- func ImportFactory[M types.Model](cfg ...*types.ControllerConfig[M]) gin.HandlerFunc
- func List[M types.Model](c *gin.Context)
- func ListFactory[M types.Model](cfg ...*types.ControllerConfig[M]) gin.HandlerFunc
- func PageID(c *gin.Context)
- func Update[M types.Model](c *gin.Context)
- func UpdateFactory[M types.Model](cfg ...*types.ControllerConfig[M]) gin.HandlerFunc
- func UpdatePartial[M types.Model](c *gin.Context)
- func UpdatePartialFactory[M types.Model](cfg ...*types.ControllerConfig[M]) gin.HandlerFunc
Constants ¶
const ( TOKEN = "token" ACCESS_TOKEN = "access_token" REFRESH_TOKEN = "refresh_token" NAME = "name" ID = "id" SESSION_ID = "session_id" )
const ( MAX_AVATAR_SIZE = 1024 * 1024 * 2 // 2M MAX_IMPORT_SIZE = 5 * 1024 * 1024 // 5M MAX_UPLOAD_SIZE = 1024 * 1024 * 100 // 100M )
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 ¶
var Column = new(column)
var PAGE_ID = time.Now().Unix()
var Portal = new(portal)
var Probe = new(probe)
var Upload = new(upload)
var User = new(user)
Functions ¶
func Create ¶
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 ¶
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 ¶
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 ¶
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 ImportFactory ¶
func ImportFactory[M types.Model](cfg ...*types.ControllerConfig[M]) gin.HandlerFunc
ImportFactory
func List ¶
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 Update ¶
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 ¶
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.