refactor: chat role manage for admin is ready

This commit is contained in:
RockYang
2023-06-20 11:46:13 +08:00
parent d244ad9983
commit f593526bd4
10 changed files with 175 additions and 64 deletions

View File

@@ -23,6 +23,10 @@ func ERROR(c *gin.Context, messages ...string) {
}
}
func HACKER(c *gin.Context) {
c.JSON(http.StatusOK, types.BizVo{Code: types.Failed, Message: "Hacker attempt!!!"})
}
func NotAuth(c *gin.Context) {
c.JSON(http.StatusOK, types.BizVo{Code: types.NotAuthorized, Message: "Not Authorized"})
}

View File

@@ -109,13 +109,18 @@ func CopyObject(src interface{}, dst interface{}) error {
if err == nil {
value.Set(reflect.ValueOf(v2).Elem())
}
// string to map, struct, slice
// map, struct, slice to string
} else if (field.Type.Kind() == reflect.Struct ||
field.Type.Kind() == reflect.Map ||
field.Type.Kind() == reflect.Slice) && value.Type().Kind() == reflect.String {
ba, err := json.Marshal(v.Interface())
if err == nil {
value.Set(reflect.ValueOf(string(ba)))
val := string(ba)
if strings.Contains(val, "{") {
value.Set(reflect.ValueOf(string(ba)))
} else {
value.Set(reflect.ValueOf(""))
}
}
} else { // 简单数据类型的强制类型转换
switch value.Kind() {