mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-27 11:01:28 +00:00
32 lines
435 B
Go
32 lines
435 B
Go
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)
|
|
}
|
|
})
|
|
}
|