gorm升级到v2版本

This commit is contained in:
linwenxiang committed 2020-08-27 11:17:15 +08:00
1 parent 93cfe443d6
commit 60c7496f7b
56 files changed
+630 -477

No files matched your search

+2 -2
View File
@@ -3,10 +3,10 @@ package mycasbin
import (
"github.com/casbin/casbin/v2"
"github.com/casbin/casbin/v2/model"
gormAdapter "github.com/casbin/gorm-adapter/v2"
gormAdapter "github.com/casbin/gorm-adapter/v3"
_ "github.com/go-sql-driver/mysql"
"log"
"go-admin/global"
"log"
)
// Initialize the model from a string.
-1
View File
@@ -4,7 +4,6 @@ import (
"github.com/robfig/cron/v3"
)
// newWithSeconds returns a Cron with the seconds field enabled.
func NewWithSeconds() *cron.Cron {
secondParser := cron.NewParser(cron.Second | cron.Minute |
+21 -16
View File
@@ -5,14 +5,13 @@ import (
"time"
)
// api结构体
type APIException struct {
Code int `json:"code"`
Success bool `json:"success"`
Msg string `json:"msg"`
Timestamp int64 `json:"timestamp"`
Result interface{} `json:"result"`
Code int `json:"code"`
Success bool `json:"success"`
Msg string `json:"msg"`
Timestamp int64 `json:"timestamp"`
Result interface{} `json:"result"`
}
// 实现接口
@@ -20,36 +19,42 @@ func (e *APIException) Error() string {
return e.Msg
}
func newAPIException(code int,msg string,data interface{},success bool) *APIException {
func newAPIException(code int, msg string, data interface{}, success bool) *APIException {
return &APIException{
Code: code,
Success: success,
Msg: msg,
Timestamp: time.Now().Unix(),
Result: data,
Result: data,
}
}
// 500 错误处理
func ServerError() *APIException {
return newAPIException(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError),nil,false)
return newAPIException(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError), nil, false)
}
// 404 错误
func NotFound() *APIException {
return newAPIException(http.StatusNotFound, http.StatusText(http.StatusNotFound),nil,false)
return newAPIException(http.StatusNotFound, http.StatusText(http.StatusNotFound), nil, false)
}
// 未知错误
func UnknownError(message string) *APIException {
return newAPIException(http.StatusForbidden, message,nil,false)
return newAPIException(http.StatusForbidden, message, nil, false)
}
// 参数错误
func ParameterError(message string) *APIException {
return newAPIException(http.StatusBadRequest, message,nil,false)
return newAPIException(http.StatusBadRequest, message, nil, false)
}
// 授权错误
func AuthError(message string) *APIException {
return newAPIException(http.StatusBadRequest, message,nil,false)
return newAPIException(http.StatusBadRequest, message, nil, false)
}
// 200
func ResponseJson(message string,data interface{},success bool) *APIException {
return newAPIException(http.StatusOK,message,data,success)
}
func ResponseJson(message string, data interface{}, success bool) *APIException {
return newAPIException(http.StatusOK, message, data, success)
}
+2 -5
View File
@@ -23,7 +23,7 @@ func IsStringEmpty(str string) bool {
func GetUUID() string {
u := uuid.NewV4()
return strings.ReplaceAll(u.String(),"-","")
return strings.ReplaceAll(u.String(), "-", "")
}
func PathExists(path string) bool {
@@ -76,9 +76,6 @@ func GetCurrentTimeStamp() int64 {
return time.Now().UnixNano() / 1e6
}
//slice去重
func RemoveRepByMap(slc []string) []string {
result := []string{}
@@ -91,4 +88,4 @@ func RemoveRepByMap(slc []string) []string {
}
}
return result
}
}
+1 -1
View File
@@ -76,7 +76,7 @@ func (c *Client) Read(cxt context.Context) {
// 写信息,从 channel 变量 Send 中读取数据写入 websocket 连接
func (c *Client) Write(cxt context.Context) {
defer func(cxt context.Context, ) {
defer func(cxt context.Context) {
log.Printf("client [%s] disconnect", c.Id)
if err := c.Socket.Close(); err != nil {
log.Printf("client [%s] disconnect err: %s", c.Id, err)