forked from gonelist/gonelist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
100 lines (92 loc) · 2.43 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import (
"flag"
"fmt"
"net/http"
"os"
"runtime"
"time"
log "github.com/sirupsen/logrus"
"gonelist/conf"
"gonelist/pkg/static"
"gonelist/routers"
"gonelist/routers/webdav"
"gonelist/service/onedrive"
"gonelist/service/onedrive/auth"
)
func main() {
confPath := flag.String("conf", "config.yml", "指定配置文件路径")
versionB := flag.Bool("version", false, "Show current version of gonelist.")
debugB := flag.Bool("debug", false, "debug log level")
getStatic := flag.Bool("static", false, "download the static files")
flag.Parse()
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
TimestampFormat: "2006-01-02 15:04:05",
})
if *versionB {
versionPrint()
return
}
if *debugB {
log.SetLevel(log.DebugLevel)
}
if *getStatic {
err := static.DownloadStatic(gVersion)
if err != nil {
log.Errorln("文件下载失败" + err.Error())
return
}
log.Infoln("文件下载完成,请重启程序")
os.Exit(3)
}
// 加载 config.yml
if err := conf.LoadUserConfig(*confPath); err != nil {
log.Fatal(err)
}
// 处理用户定义的 passList
onedrive.InitPass(conf.UserSet)
// 设置 onedrive 的相关配置,如果有 .token 那么会在这儿进行处理初始化
// 否则在端口绑定之后通过接口登陆之后初始化
onedrive.SetROOTUrl(conf.UserSet)
auth.SetOnedriveInfo(conf.UserSet, onedrive.InitOnedrive)
println(onedrive.GetDrive())
// 设置 version
if Version != "" {
conf.UserSet.Version = Version
} else {
conf.UserSet.Version = gVersion
}
// 处理端口绑定
Addr := conf.GetBindAddr(conf.UserSet.Server.BindGlobal, conf.UserSet.Server.Port)
// 启动服务器
server := &http.Server{
Addr: Addr,
Handler: routers.InitRouter(),
ReadTimeout: 60 * time.Second,
WriteTimeout: 60 * time.Second,
MaxHeaderBytes: 1 << 20,
}
if conf.UserSet.WebDav.Enable {
go webdav.DavInit()
}
panic(server.ListenAndServe())
}
var (
gVersion = "v0.6.0"
Version string
gitCommit string
gitTreeState = "" // state of git tree, either "clean" or "dirty"
buildDate = "1970-01-01T00:00:00Z" // build date, output of $(date +'%Y-%m-%dT%H:%M:%S')
)
func versionPrint() {
fmt.Printf(`Name: gonelist
Version: %s
CommitID: %s
GitTreeState: %s
BuildDate: %s
GoVersion: %s
Compiler: %s
Platform: %s/%s
`, Version, gitCommit, gitTreeState, buildDate, runtime.Version(), runtime.Compiler, runtime.GOOS, runtime.GOARCH)
}