123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package utils
- import (
- "os"
- "path/filepath"
- "reflect"
- "strings"
- )
- func FileMove(src string, dst string) (err error) {
- if dst == "" {
- return nil
- }
- src, err = filepath.Abs(src)
- if err != nil {
- return err
- }
- dst, err = filepath.Abs(dst)
- if err != nil {
- return err
- }
- var revoke = false
- dir := filepath.Dir(dst)
- Redirect:
- _, err = os.Stat(dir)
- if err != nil {
- err = os.MkdirAll(dir, 0755)
- if err != nil {
- return err
- }
- if !revoke {
- revoke = true
- goto Redirect
- }
- }
- return os.Rename(src, dst)
- }
- func DeLFile(filePath string) error {
- return os.RemoveAll(filePath)
- }
- 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
- }
|