package static_path import ( "os" "path/filepath" "runtime" ) type fileDir struct { Root string // 资源根目录 Static string Excel string Default string // 默认图片的目录 Photo string Video string // 商品视频目录 Temp string RootPhp string } var Dir *fileDir func init() { f := &fileDir{} f.Static = "/static" f.Excel = "/excel" f.Photo = "/photo" f.Default = "/default" f.Video = "/video" f.Temp = "/temp" if runtime.GOOS == "linux" { f.Root = "/www/wwwroot/recook_v2/static" f.RootPhp = "/www/wwwroot/testsp.reecook.cn/public" _, err := os.Stat(f.Root) if os.IsNotExist(err) { err := os.Mkdir(f.Root, 0777) if err != nil { panic(err) } } var paths = []string{f.Excel, f.Photo, f.Default, f.Video, f.Temp} for i := range paths { path := filepath.Join(f.Root, paths[i]) _, err := os.Stat(path) if os.IsNotExist(err) { err := os.Mkdir(path, 0777) if err != nil { panic(err) } } } } else { f.Root = "/Users/datang/backend_v2/static" //f.Root = "/Users/mac/Desktop/recookMain/static" //f.Root = "/Users/apple/go/src/recookMain/static" } Dir = f }