Files
ai/models/ListView.go
2023-04-18 15:53:13 +08:00

33 lines
648 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package models
import (
"encoding/json"
"log"
)
type ListView struct {
Code int `json:"code"`
Page int `json:"page"`
PageSize int `json:"page_size"`
Total int `json:"total"`
Next bool `json:"next"`
List []interface{} `json:"list"`
}
// 輸出JSON給瀏覽器
func (listview *ListView) ToJson() []byte {
// 即使list爲空也要返回空的JSON數組
if listview.List == nil {
listview.List = make([]interface{}, 0)
}
// 輸出格式化的JSON
b, err := json.MarshalIndent(listview, "", " ")
if err != nil {
log.Println(err)
return nil
}
return b
}