-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
79 lines (67 loc) · 1.7 KB
/
Copy pathmain.go
File metadata and controls
79 lines (67 loc) · 1.7 KB
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
79
package main
import (
"os"
"path/filepath"
_ "github.com/cicbyte/wekeep/internal/packed"
//重要 需要导入数据库驱动
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
// SQLite数据库驱动,如果需要支持需要go get -u github.com/gogf/gf/contrib/drivers/sqlite/v2
_ "github.com/gogf/gf/contrib/drivers/sqlite/v2"
"github.com/gogf/gf/v2/os/gbuild"
"github.com/gogf/gf/v2/os/gctx"
"github.com/cicbyte/wekeep/internal/cmd"
)
// 默认配置(首次运行时自动创建,用户可修改)
const defaultConfig = `# WeKeep 配置文件(可修改)
server:
address: ":8000"
logPath: "log/server"
logStdout: true
errorStack: true
errorLogEnabled: true
errorLogPattern: "error-{Ymd}.log"
accessLogEnabled: true
accessLogPattern: "access-{Ymd}.log"
logger:
path: "log/run"
file: "{Y-m-d}.log"
level: "all"
stdout: true
database:
default:
link: "sqlite::@file(db/wekeep.db)"
storage:
type: "local"
local:
basePath: "uploads"
baseURL: "/uploads"
image:
maxFileSize: 10485760
pathPrefix: "articles/images"
migration:
enabled: false
search:
enabled: false
`
func init() {
// 通过 gbuild 编译变量判断是否为生产构建(gf build 会注入,gf run 不会)
if gbuild.Get(gbuild.BuiltVersion) != nil {
if exe, err := os.Executable(); err == nil {
if dir := filepath.Dir(exe); dir != "" {
os.Chdir(dir)
}
}
ensureDefaultConfig()
}
}
func ensureDefaultConfig() {
configPath := "manifest/config/config.yaml"
if _, err := os.Stat(configPath); err == nil {
return
}
os.MkdirAll(filepath.Dir(configPath), 0755)
os.WriteFile(configPath, []byte(defaultConfig), 0644)
}
func main() {
cmd.Main.Run(gctx.GetInitCtx())
}