mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-16 15:42:21 +08:00
Uniq deprecated notes
This commit is contained in:
parent
88099a304a
commit
21faadb992
|
@ -67,5 +67,5 @@ func preRun(cmd *cobra.Command, args []string) {
|
||||||
if len(configPaths) == 0 && len(configDirectories) == 0 {
|
if len(configPaths) == 0 && len(configDirectories) == 0 {
|
||||||
configPaths = append(configPaths, "config.json")
|
configPaths = append(configPaths, "config.json")
|
||||||
}
|
}
|
||||||
globalCtx = service.ContextWith(globalCtx, deprecated.NewEnvManager(log.StdLogger()))
|
globalCtx = service.ContextWith(globalCtx, deprecated.NewStderrManager(log.StdLogger()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ func check() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(globalCtx)
|
||||||
instance, err := box.New(box.Options{
|
instance, err := box.New(box.Options{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
Options: options,
|
Options: options,
|
||||||
|
|
|
@ -7,15 +7,23 @@ import (
|
||||||
"github.com/sagernet/sing/common/logger"
|
"github.com/sagernet/sing/common/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type envManager struct {
|
type stderrManager struct {
|
||||||
logger logger.Logger
|
logger logger.Logger
|
||||||
|
reported map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEnvManager(logger logger.Logger) Manager {
|
func NewStderrManager(logger logger.Logger) Manager {
|
||||||
return &envManager{logger: logger}
|
return &stderrManager{
|
||||||
|
logger: logger,
|
||||||
|
reported: make(map[string]bool),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *envManager) ReportDeprecated(feature Note) {
|
func (f *stderrManager) ReportDeprecated(feature Note) {
|
||||||
|
if f.reported[feature.Name] {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
f.reported[feature.Name] = true
|
||||||
if !feature.Impending() {
|
if !feature.Impending() {
|
||||||
f.logger.Warn(feature.MessageWithLink())
|
f.logger.Warn(feature.MessageWithLink())
|
||||||
return
|
return
|
|
@ -4,27 +4,28 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/sagernet/sing-box/experimental/deprecated"
|
"github.com/sagernet/sing-box/experimental/deprecated"
|
||||||
|
"github.com/sagernet/sing/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ deprecated.Manager = (*deprecatedManager)(nil)
|
var _ deprecated.Manager = (*deprecatedManager)(nil)
|
||||||
|
|
||||||
type deprecatedManager struct {
|
type deprecatedManager struct {
|
||||||
access sync.Mutex
|
access sync.Mutex
|
||||||
features []deprecated.Note
|
notes []deprecated.Note
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *deprecatedManager) ReportDeprecated(feature deprecated.Note) {
|
func (m *deprecatedManager) ReportDeprecated(feature deprecated.Note) {
|
||||||
m.access.Lock()
|
m.access.Lock()
|
||||||
defer m.access.Unlock()
|
defer m.access.Unlock()
|
||||||
m.features = append(m.features, feature)
|
m.notes = common.Uniq(append(m.notes, feature))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *deprecatedManager) Get() []deprecated.Note {
|
func (m *deprecatedManager) Get() []deprecated.Note {
|
||||||
m.access.Lock()
|
m.access.Lock()
|
||||||
defer m.access.Unlock()
|
defer m.access.Unlock()
|
||||||
features := m.features
|
notes := m.notes
|
||||||
m.features = nil
|
m.notes = nil
|
||||||
return features
|
return notes
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = deprecated.Note(DeprecatedNote{})
|
var _ = deprecated.Note(DeprecatedNote{})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user