提交 bfb5b34e 编写于 作者: H HFO4

Fix: concurrent logging lock / Feat: listen SSL (#287)

上级 e038350c
...@@ -37,11 +37,13 @@ func CheckUpdate() { ...@@ -37,11 +37,13 @@ func CheckUpdate() {
res, err := client.Request("GET", "https://api.github.com/repos/cloudreve/cloudreve/releases", nil).GetResponse() res, err := client.Request("GET", "https://api.github.com/repos/cloudreve/cloudreve/releases", nil).GetResponse()
if err != nil { if err != nil {
util.Log().Warning("更新检查失败, %s", err) util.Log().Warning("更新检查失败, %s", err)
return
} }
var list []GitHubRelease var list []GitHubRelease
if err := json.Unmarshal([]byte(res), &list); err != nil { if err := json.Unmarshal([]byte(res), &list); err != nil {
util.Log().Warning("更新检查失败, %s", err) util.Log().Warning("更新检查失败, %s", err)
return
} }
if len(list) > 0 { if len(list) > 0 {
......
...@@ -18,6 +18,18 @@ func init() { ...@@ -18,6 +18,18 @@ func init() {
func main() { func main() {
api := routers.InitRouter() 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)
}
}()
}
util.Log().Info("开始监听 %s", conf.SystemConfig.Listen) util.Log().Info("开始监听 %s", conf.SystemConfig.Listen)
if err := api.Run(conf.SystemConfig.Listen); err != nil { if err := api.Run(conf.SystemConfig.Listen); err != nil {
util.Log().Error("无法监听[%s],%s", conf.SystemConfig.Listen, err) util.Log().Error("无法监听[%s],%s", conf.SystemConfig.Listen, err)
......
...@@ -27,6 +27,12 @@ type system struct { ...@@ -27,6 +27,12 @@ type system struct {
HashIDSalt string HashIDSalt string
} }
type ssl struct {
CertPath string `validate:"omitempty,required"`
KeyPath string `validate:"omitempty,required"`
Listen string `validate:"required"`
}
// slave 作为slave存储端配置 // slave 作为slave存储端配置
type slave struct { type slave struct {
Secret string `validate:"omitempty,gte=64"` Secret string `validate:"omitempty,gte=64"`
...@@ -113,6 +119,7 @@ func Init(path string) { ...@@ -113,6 +119,7 @@ func Init(path string) {
sections := map[string]interface{}{ sections := map[string]interface{}{
"Database": DatabaseConfig, "Database": DatabaseConfig,
"System": SystemConfig, "System": SystemConfig,
"SSL": SSLConfig,
"Captcha": CaptchaConfig, "Captcha": CaptchaConfig,
"Redis": RedisConfig, "Redis": RedisConfig,
"Thumbnail": ThumbConfig, "Thumbnail": ThumbConfig,
......
...@@ -59,3 +59,9 @@ var SlaveConfig = &slave{ ...@@ -59,3 +59,9 @@ var SlaveConfig = &slave{
CallbackTimeout: 20, CallbackTimeout: 20,
SignatureTTL: 60, SignatureTTL: 60,
} }
var SSLConfig = &ssl{
Listen: ":443",
CertPath: "",
KeyPath: "",
}
...@@ -3,6 +3,7 @@ package util ...@@ -3,6 +3,7 @@ package util
import ( import (
"fmt" "fmt"
"github.com/fatih/color" "github.com/fatih/color"
"sync"
"time" "time"
) )
...@@ -23,6 +24,7 @@ var Level = LevelDebug ...@@ -23,6 +24,7 @@ var Level = LevelDebug
// Logger 日志 // Logger 日志
type Logger struct { type Logger struct {
level int level int
mu sync.Mutex
} }
// 日志颜色 // 日志颜色
...@@ -49,6 +51,10 @@ func (ll *Logger) Println(prefix string, msg string) { ...@@ -49,6 +51,10 @@ func (ll *Logger) Println(prefix string, msg string) {
// color.NoColor = false // color.NoColor = false
c := color.New() c := color.New()
ll.mu.Lock()
defer ll.mu.Unlock()
_, _ = c.Printf( _, _ = c.Printf(
"%s%s %s %s\n", "%s%s %s %s\n",
colors[prefix]("["+prefix+"]"), colors[prefix]("["+prefix+"]"),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册