Cloudreve/main.go

59 lines
1.4 KiB
Go
Raw Normal View History

2019-11-04 07:30:12 -05:00
package main
2019-11-04 23:31:22 -05:00
import (
2020-03-09 03:53:01 -05:00
"flag"
"github.com/cloudreve/Cloudreve/v3/bootstrap"
"github.com/cloudreve/Cloudreve/v3/pkg/conf"
"github.com/cloudreve/Cloudreve/v3/pkg/util"
"github.com/cloudreve/Cloudreve/v3/routers"
2019-11-04 23:31:22 -05:00
)
2019-11-04 07:30:12 -05:00
2020-05-23 00:57:02 -05:00
var (
isEject bool
confPath string
)
2020-03-09 03:53:01 -05:00
2019-11-07 02:56:05 -05:00
func init() {
2020-03-10 21:32:35 -05:00
flag.StringVar(&confPath, "c", util.RelativePath("conf.ini"), "配置文件路径")
2020-05-23 00:57:02 -05:00
flag.BoolVar(&isEject, "eject", false, "导出内置静态资源")
2020-03-09 03:53:01 -05:00
flag.Parse()
bootstrap.Init(confPath)
2019-11-07 02:56:05 -05:00
}
2019-11-04 07:30:12 -05:00
func main() {
2020-05-23 00:57:02 -05:00
if isEject {
// 开始导出内置静态资源文件
bootstrap.Eject()
return
}
2019-11-04 23:31:22 -05: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)
}
}()
}
// 如果启用了Unix
if conf.UnixConfig.Listen != "" {
go func() {
util.Log().Info("开始监听 %s", conf.UnixConfig.Listen)
if err := api.RunUnix(conf.UnixConfig.Listen); err != nil {
util.Log().Error("无法监听[%s]%s", conf.UnixConfig.Listen, err)
}
}()
}
2020-03-09 03:53:01 -05: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 07:30:12 -05:00
}