-
Notifications
You must be signed in to change notification settings - Fork 750
/
Copy pathmain.go
78 lines (62 loc) · 1.38 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"io/fs"
"github.com/sjqzhang/go-fastdfs/cmd/doc"
"github.com/sjqzhang/go-fastdfs/cmd/server"
"github.com/sjqzhang/go-fastdfs/cmd/version"
dfs "github.com/sjqzhang/go-fastdfs/server"
"github.com/spf13/cobra"
//_ "go.uber.org/automaxprocs" // 根据容器配额设置 maxprocs
"embed"
"io"
_ "net/http/pprof" // 注册 pprof 接口
"os"
)
var (
VERSION string
BUILD_TIME string
GO_VERSION string
GIT_VERSION string
)
//go:embed static
var staticFs embed.FS
func init() {
extractFilesIfNotExists(staticFs, "static", "./static")
}
func extractFilesIfNotExists(fs2 embed.FS, sourceDir, targetDir string) error {
// 检查目标目录是否存在
return fs.WalkDir(fs2, sourceDir, func(path string, d fs.DirEntry, err error) error {
// 如果是目录,则创建目录
if d.IsDir() {
return os.MkdirAll(path, 0755)
}
// 打开嵌入的文件
ff, err := fs2.Open(path)
if err != nil {
return err
}
defer ff.Close()
// 创建目标文件
tf, err := os.Create(path)
if err != nil {
return err
}
defer tf.Close()
// 复制内容
_, err = io.Copy(tf, ff)
return err
})
}
func main() {
dfs.VERSION = VERSION
dfs.BUILD_TIME = BUILD_TIME
dfs.GO_VERSION = GO_VERSION
dfs.GIT_VERSION = GIT_VERSION
root := cobra.Command{Use: "fileserver"}
root.AddCommand(
version.Cmd,
doc.Cmd,
server.Cmd,
)
root.Execute()
}