Cloudreve/main.go

48 lines
1.1 KiB
Go
Raw Normal View History

2019-11-04 20:30:12 +08:00
package main
2019-11-05 12:31:22 +08:00
import (
2020-03-09 16:53:01 +08:00
"flag"
"github.com/HFO4/cloudreve/bootstrap"
2019-11-16 16:11:37 +08:00
"github.com/HFO4/cloudreve/pkg/conf"
2020-03-09 16:53:01 +08:00
"github.com/HFO4/cloudreve/pkg/util"
2019-11-16 16:11:37 +08:00
"github.com/HFO4/cloudreve/routers"
2019-11-05 12:31:22 +08:00
)
2019-11-04 20:30:12 +08:00
2020-05-23 13:57:02 +08:00
var (
isEject bool
confPath string
)
2020-03-09 16:53:01 +08:00
2019-11-07 15:56:05 +08:00
func init() {
2020-03-11 10:32:35 +08:00
flag.StringVar(&confPath, "c", util.RelativePath("conf.ini"), "配置文件路径")
2020-05-23 13:57:02 +08:00
flag.BoolVar(&isEject, "eject", false, "导出内置静态资源")
2020-03-09 16:53:01 +08:00
flag.Parse()
bootstrap.Init(confPath)
2019-11-07 15:56:05 +08:00
}
2019-11-04 20:30:12 +08:00
func main() {
2020-05-23 13:57:02 +08:00
if isEject {
// 开始导出内置静态资源文件
bootstrap.Eject()
return
}
2019-11-05 12:31:22 +08:00
api := routers.InitRouter()
// 如果启用了SSL
if conf.SSLConfig.CertPath != "" {
go func() {
util.Log().Info("开始监听 %s", conf.SSLConfig.Listen)
if err := api.RunTLS(conf.SSLConfig.Listen,
conf.SSLConfig.CertPath, conf.SSLConfig.KeyPath); err != nil {
util.Log().Error("无法监听[%s]%s", conf.SSLConfig.Listen, err)
}
}()
}
2020-03-09 16:53:01 +08:00
util.Log().Info("开始监听 %s", conf.SystemConfig.Listen)
if err := api.Run(conf.SystemConfig.Listen); err != nil {
util.Log().Error("无法监听[%s]%s", conf.SystemConfig.Listen, err)
}
2019-11-04 20:30:12 +08:00
}