File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package core
33import (
44 "fmt"
55 "gin-vue-admin/global"
6+ _ "gin-vue-admin/packfile"
67 "github.com/fsnotify/fsnotify"
78 "github.com/spf13/viper"
89)
Original file line number Diff line number Diff line change 1+ // +build !packfile
2+
3+ package packfile
Original file line number Diff line number Diff line change 1+ // +build packfile
2+
3+ package packfile
4+
5+ import (
6+ "fmt"
7+ "io/ioutil"
8+ "os"
9+ "path/filepath"
10+ "strings"
11+ )
12+
13+ //go:generate go-bindata -o=staticFile.go -pkg=packfile -tags=packfile ../resource/... ../config.yaml
14+
15+ func writeFile (path string , data []byte ) {
16+ // 如果文件夹不存在,预先创建文件夹
17+ if lastSeparator := strings .LastIndex (path , "/" ); lastSeparator != - 1 {
18+ dirPath := path [:lastSeparator ]
19+ if _ , err := os .Stat (dirPath ); err != nil && os .IsNotExist (err ) {
20+ os .MkdirAll (dirPath , os .ModePerm )
21+ }
22+ }
23+
24+ // 已存在的文件,不应该覆盖重写,可能在前端更改了配置文件等
25+ if _ , err := os .Stat (path ); os .IsNotExist (err ) {
26+ if err2 := ioutil .WriteFile (path , data , os .ModePerm ); err2 != nil {
27+ fmt .Printf ("Write file failed: %s\n " , path )
28+ }
29+ } else {
30+ fmt .Printf ("File exist, skip: %s\n " , path )
31+ }
32+ }
33+
34+ func init () {
35+ for key := range _bindata {
36+ filePath , _ := filepath .Abs (strings .TrimPrefix (key , "." ))
37+ data , err := Asset (key )
38+ if err != nil {
39+ // Asset was not found.
40+ fmt .Printf ("Fail to find: %s\n " , filePath )
41+ } else {
42+ writeFile (filePath , data )
43+ }
44+ }
45+ }
You can’t perform that action at this time.
0 commit comments