2024-10-18 09:58:03 +08:00
|
|
|
package deprecated
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/sagernet/sing/common/logger"
|
|
|
|
)
|
|
|
|
|
2024-11-07 19:58:46 +08:00
|
|
|
type stderrManager struct {
|
|
|
|
logger logger.Logger
|
|
|
|
reported map[string]bool
|
2024-10-18 09:58:03 +08:00
|
|
|
}
|
|
|
|
|
2024-11-07 19:58:46 +08:00
|
|
|
func NewStderrManager(logger logger.Logger) Manager {
|
|
|
|
return &stderrManager{
|
|
|
|
logger: logger,
|
|
|
|
reported: make(map[string]bool),
|
|
|
|
}
|
2024-10-18 09:58:03 +08:00
|
|
|
}
|
|
|
|
|
2024-11-07 19:58:46 +08:00
|
|
|
func (f *stderrManager) ReportDeprecated(feature Note) {
|
|
|
|
if f.reported[feature.Name] {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
f.reported[feature.Name] = true
|
2024-10-18 09:58:03 +08:00
|
|
|
if !feature.Impending() {
|
|
|
|
f.logger.Warn(feature.MessageWithLink())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
enable, enableErr := strconv.ParseBool(os.Getenv("ENABLE_DEPRECATED_" + feature.EnvName))
|
|
|
|
if enableErr == nil && enable {
|
|
|
|
f.logger.Warn(feature.MessageWithLink())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
f.logger.Error(feature.MessageWithLink())
|
|
|
|
f.logger.Fatal("to continuing using this feature, set ENABLE_DEPRECATED_" + feature.EnvName + "=true")
|
|
|
|
}
|