Add runtime warnings

This commit is contained in:
世界
2022-07-25 07:19:15 +08:00
parent 29c329dc52
commit 32e2730ec6
29 changed files with 677 additions and 16 deletions
+31
View File
@@ -0,0 +1,31 @@
package warning
import (
"sync"
"github.com/sagernet/sing-box/log"
)
type Warning struct {
logger log.Logger
check CheckFunc
message string
checkOnce sync.Once
}
type CheckFunc = func() bool
func New(checkFunc CheckFunc, message string) Warning {
return Warning{
check: checkFunc,
message: message,
}
}
func (w *Warning) Check() {
w.checkOnce.Do(func() {
if w.check() {
log.Warn(w.message)
}
})
}