ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 部分代码 ### 数据库链接 ``` Db, err = sqlx.Connect(`mysql`, `user:password@tcp(host:port)/database?charset=utf8&parseTime=true&loc=Local`) ``` ### utils ``` package utils //standard format type result struct { State stat `json:"state"` Msg string `json:"msg"` Data interface{} `json:"data"` } //page format //Message type list struct { Count int `json:"count"` Item interface{} `json:"item"` } type stat int const ( StSucc stat = 200 //正常 StFail stat = 300 //失败 StErrIpt stat = 310 //输入数据有误 StErrOpt stat = 320 //无数据返回 ) const ( FormatTime = "15:04:05" FormatDate = "2006-01-02" FormatDateTime = "2006-01-02 15:04:05" ) func newRes(st stat, msg string, data ...interface{}) *result { if len(data) > 0 { return &result{ State: st, Msg: msg, Data: data[0], } } return &result{ State: st, Msg: msg, } } func NewSucc(msg string, data ...interface{}) *result { return newRes(StSucc, msg, data...) } func NewFail(msg string, data ...interface{}) *result { return newRes(StFail, msg, data...) } func NewErr(st stat, msg string, data ...interface{}) *result { return newRes(st, msg, data...) } func NewList(msg string, item interface{}, count int) *result { return &result{ State: StSucc, Msg: msg, Data: list{ Item: item, Count: count, }, } } ```