package
0.0.0-20241018081110-072913901059
Repository: https://github.com/oldmacloud/crud.git
Documentation: pkg.go.dev
# Functions
CreateHandler handles
POST /T
creates a new model T, responds with the created model T if successful.
CreateNestedHandler handles
POST /P/:parentIDRouteParam/T
where: - P is the parent model, T is the child model - parentIDRouteParam is the route param name of the parent model P - field is the field name of the child model T in the parent model P
responds with the updated parent model P
Request body: - {...} // fields of the child model T
Response: - 200 OK: { P: {...} } - 400 Bad Request: { error: "request band failed" } - 422 Unprocessable Entity: { error: "create process failed" }.
DeleteHandler handles
DELETE /T/:idParam
Deletes the model T with the given id.
DeleteNestedHandler handles
DELETE /P/:parentIdParam/T/:childIdParam
where: - P is the parent model, T is the child model - parentIdParam is the route param name of the parent model P - childIdParam is the route param name of the child model T in the parent model P - field is the field name of the child model T in the parent model P
Request body: none
Response: - 200 OK: { deleted: true } - 400 Bad Request: { error: "missing id" } - 422 Unprocessable Entity: { error: "delete process failed" }.
ErrorResponseBody builds the error response body:
{ error: "error message" }.
GetByIDHandler handles
GET /T/:idParam
QueryOptions (See GetRequestOptions for more details): preload
Response: - 200 OK: { T: {...} } - 400 Bad Request: { error: "request band failed" } - 422 Unprocessable Entity: { error: "get process failed" }.
GetFieldHandler handles
GET /T/:idParam/field
QueryOptions (See GetRequestOptions for more details):
limit, offset, order_by, desc, filter_by, filter_value, preload, total.
GetListHandler handles
GET /T
It returns a list of models.
ResponseError writes an error response to client in JSON.
ResponseSuccess writes a success response to client in JSON.
SuccessResponseBody builds the success response body:
{ `model`: { ..
UpdateHandler handles
PUT /T/:idParam
Updates the model T with the given id.
# Constants
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Variables
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Structs
GetRequestOptions is the query options (?opt=val) for GET requests:
limit=10&offset=4& # pagination order_by=id&desc=true& # ordering filter_by=name&filter_value=John& # filtering total=true& # return total count (all available records under the filter, ignoring pagination) preload=Product&preload=Product.Manufacturer # preloading: loads nested models as well
It is used in GetListHandler, GetByIDHandler and GetFieldHandler, to bind the query parameters in the GET request url.