commit
da2ff794ef
@ -0,0 +1,52 @@
|
||||
package CommonUtil
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type Items struct {
|
||||
data interface{}
|
||||
field string
|
||||
}
|
||||
|
||||
func (items *Items) Len() int {
|
||||
if reflect.ValueOf(items.data).Kind() != reflect.Slice {
|
||||
return -1
|
||||
}
|
||||
return reflect.ValueOf(items.data).Len()
|
||||
}
|
||||
|
||||
func (items *Items) Less(i, j int) bool {
|
||||
a := reflect.ValueOf(items.data).Index(i)
|
||||
b := reflect.ValueOf(items.data).Index(j)
|
||||
if a.Kind() == reflect.Ptr {
|
||||
a = a.Elem()
|
||||
}
|
||||
if b.Kind() == reflect.Ptr {
|
||||
b = b.Elem()
|
||||
}
|
||||
va := a.FieldByName(items.field).Int()
|
||||
vb := b.FieldByName(items.field).Int()
|
||||
return va < vb
|
||||
}
|
||||
|
||||
func (items *Items) Swap(i, j int) {
|
||||
reflect.Swapper(items.data)(i, j)
|
||||
}
|
||||
|
||||
func SortItems(i interface{}, str string, sortType string) {
|
||||
if reflect.ValueOf(i).Kind() != reflect.Slice {
|
||||
return
|
||||
}
|
||||
a := &Items{
|
||||
data: i,
|
||||
field: str,
|
||||
}
|
||||
if sortType == "desc" {
|
||||
sort.Sort(sort.Reverse(a))
|
||||
} else {
|
||||
sort.Sort(a)
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -1,63 +0,0 @@
|
||||
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
||||
// This file was generated by swaggo/swag at
|
||||
// 2020-05-20 14:45:12.3054401 +0800 CST m=+0.096772501
|
||||
|
||||
package docs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/template"
|
||||
"github.com/swaggo/swag"
|
||||
)
|
||||
|
||||
var doc = `{{.json}}`
|
||||
|
||||
type swaggerInfo struct {
|
||||
Version string
|
||||
Host string
|
||||
BasePath string
|
||||
Schemes []string
|
||||
Title string
|
||||
Description string
|
||||
}
|
||||
|
||||
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
||||
var SwaggerInfo = swaggerInfo{
|
||||
Version: "1.0",
|
||||
Host: "127.0.0.1:8002",
|
||||
BasePath: "",
|
||||
Schemes: []string{},
|
||||
Title: "基础数据API",
|
||||
Description: "分布式,大并发,高可用",
|
||||
}
|
||||
|
||||
type s struct{}
|
||||
|
||||
func (s *s) ReadDoc() string {
|
||||
sInfo := SwaggerInfo
|
||||
sInfo.Description = strings.Replace(sInfo.Description, "\n", "\\n", -1)
|
||||
|
||||
t, err := template.New("swagger_info").Funcs(template.FuncMap{
|
||||
"marshal": func(v interface{}) string {
|
||||
a, _ := json.Marshal(v)
|
||||
return string(a)
|
||||
},
|
||||
}).Parse(doc)
|
||||
if err != nil {
|
||||
return doc
|
||||
}
|
||||
|
||||
var tpl bytes.Buffer
|
||||
if err := t.Execute(&tpl, sInfo); err != nil {
|
||||
return doc
|
||||
}
|
||||
|
||||
return tpl.String()
|
||||
}
|
||||
|
||||
func init() {
|
||||
swag.Register(swag.Name, &s{})
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue