|
|
@ -3,6 +3,8 @@ package utils |
|
|
|
import ( |
|
|
|
"os" |
|
|
|
"path/filepath" |
|
|
|
"reflect" |
|
|
|
"strings" |
|
|
|
) |
|
|
|
|
|
|
|
//@author: [songzhibin97](https://github.com/songzhibin97)
|
|
|
@ -39,3 +41,25 @@ Redirect: |
|
|
|
} |
|
|
|
return os.Rename(src, dst) |
|
|
|
} |
|
|
|
|
|
|
|
//@author: [songzhibin97](https://github.com/songzhibin97)
|
|
|
|
//@function: TrimSpace
|
|
|
|
//@description: 去除结构体空格
|
|
|
|
//@param: target interface (target: 目标结构体,传入必须是指针类型)
|
|
|
|
//@return: err error
|
|
|
|
|
|
|
|
func TrimSpace(target interface{}) { |
|
|
|
t := reflect.TypeOf(target) |
|
|
|
if t.Kind() != reflect.Ptr { |
|
|
|
return |
|
|
|
} |
|
|
|
t = t.Elem() |
|
|
|
v := reflect.ValueOf(target).Elem() |
|
|
|
for i := 0; i < t.NumField(); i++ { |
|
|
|
switch v.Field(i).Kind() { |
|
|
|
case reflect.String: |
|
|
|
v.Field(i).SetString(strings.TrimSpace(v.Field(i).String())) |
|
|
|
} |
|
|
|
} |
|
|
|
return |
|
|
|
} |