This commit is contained in:
parent
59f831db55
commit
f80a43faf1
@ -57,8 +57,8 @@ func RunServer(config config.Config) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run runs the main loop
|
// Run runs the main loop
|
||||||
func Run(c echo.Context, config config.Config) (res DatatableOutput, err error) {
|
func Run(c echo.Context, config config.Config) (res QrzDatatableOutput, err error) {
|
||||||
qrzinputjson := new(DatatableInput)
|
qrzinputjson := new(QrzDatatableInput)
|
||||||
var count int
|
var count int
|
||||||
|
|
||||||
if err = c.Bind(qrzinputjson); err != nil {
|
if err = c.Bind(qrzinputjson); err != nil {
|
||||||
@ -95,7 +95,7 @@ func Run(c echo.Context, config config.Config) (res DatatableOutput, err error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BuildQuery builds main query
|
// BuildQuery builds main query
|
||||||
func BuildQuery(config config.Config, qrzdt DatatableInput) (rows *sqlx.Rows, err error) {
|
func BuildQuery(config config.Config, qrzdt QrzDatatableInput) (rows *sqlx.Rows, err error) {
|
||||||
var selectstatement, orderstatement, limitstatement, searchstatement string
|
var selectstatement, orderstatement, limitstatement, searchstatement string
|
||||||
|
|
||||||
selectstatement, err = SetSelectStatement(config, qrzdt)
|
selectstatement, err = SetSelectStatement(config, qrzdt)
|
||||||
@ -150,7 +150,7 @@ func BuildQueryCountTotal(config config.Config, qrzdt QrzDatatableInput) (cnt in
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetSelectStatement build the sql select statement part
|
// SetSelectStatement build the sql select statement part
|
||||||
func SetSelectStatement(config config.Config, qrzdt DatatableInput) (selectstatement string, err error) {
|
func SetSelectStatement(config config.Config, qrzdt QrzDatatableInput) (selectstatement string, err error) {
|
||||||
var cols []string
|
var cols []string
|
||||||
colre := regexp.MustCompile(`^[A-Za-z0-9]+$`)
|
colre := regexp.MustCompile(`^[A-Za-z0-9]+$`)
|
||||||
if len(qrzdt.Columns) > 0 {
|
if len(qrzdt.Columns) > 0 {
|
||||||
@ -172,7 +172,7 @@ func SetSelectStatement(config config.Config, qrzdt DatatableInput) (selectstate
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetOrderStatement build the sql order statement part
|
// SetOrderStatement build the sql order statement part
|
||||||
func SetOrderStatement(config config.Config, qrzdt DatatableInput) (orderstmt string, err error) {
|
func SetOrderStatement(config config.Config, qrzdt QrzDatatableInput) (orderstmt string, err error) {
|
||||||
var orderstmts []string
|
var orderstmts []string
|
||||||
colre := regexp.MustCompile(`^[A-Za-z0-9]+$`)
|
colre := regexp.MustCompile(`^[A-Za-z0-9]+$`)
|
||||||
orderre := regexp.MustCompile(`^(ASC|asc|DESC|desc)$`)
|
orderre := regexp.MustCompile(`^(ASC|asc|DESC|desc)$`)
|
||||||
@ -191,7 +191,7 @@ func SetOrderStatement(config config.Config, qrzdt DatatableInput) (orderstmt st
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetLimitStatement build the sql limit statement part
|
// SetLimitStatement build the sql limit statement part
|
||||||
func SetLimitStatement(config config.Config, qrzdt DatatableInput) (limitstmt string, err error) {
|
func SetLimitStatement(config config.Config, qrzdt QrzDatatableInput) (limitstmt string, err error) {
|
||||||
intre := regexp.MustCompile(`^[0-9]+$`)
|
intre := regexp.MustCompile(`^[0-9]+$`)
|
||||||
if qrzdt.Length < 1 {
|
if qrzdt.Length < 1 {
|
||||||
qrzdt.Length = 50
|
qrzdt.Length = 50
|
||||||
@ -259,8 +259,8 @@ func RunCSVExport(c echo.Context, config config.Config) (data []byte, mime strin
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// DatatableInput describes datatable query
|
// QrzDatatableInput describes datatable query
|
||||||
type DatatableInput struct {
|
type QrzDatatableInput struct {
|
||||||
Columns []struct {
|
Columns []struct {
|
||||||
Data int `json:"data"`
|
Data int `json:"data"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@ -284,8 +284,8 @@ type DatatableInput struct {
|
|||||||
Start int `json:"start"`
|
Start int `json:"start"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DatatableOutput describes datatable response
|
// QrzDatatableOutput describes datatable response
|
||||||
type DatatableOutput struct {
|
type QrzDatatableOutput struct {
|
||||||
Data [][]string `json:"data"`
|
Data [][]string `json:"data"`
|
||||||
Draw int `json:"draw"`
|
Draw int `json:"draw"`
|
||||||
RecordsTotal int `json:"recordsTotal"`
|
RecordsTotal int `json:"recordsTotal"`
|
||||||
|
Loading…
Reference in New Issue
Block a user