Add runtime warnings

This commit is contained in:
世界
2022-07-24 22:54:16 +08:00
parent 29c329dc52
commit 32e2730ec6
29 changed files with 677 additions and 16 deletions

View File

@@ -4,9 +4,22 @@ import (
"strings"
"github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing-box/common/warning"
C "github.com/sagernet/sing-box/constant"
F "github.com/sagernet/sing/common/format"
)
var (
warnUserOnNonLinux = warning.New(
func() bool { return !C.IsLinux },
"rule item `user` is only supported on Linux",
)
warnUserOnCGODisabled = warning.New(
func() bool { return !C.CGO_ENABLED },
"rule item `user` is only supported with CGO enabled, rebuild with CGO_ENABLED=1",
)
)
var _ RuleItem = (*UserItem)(nil)
type UserItem struct {
@@ -15,6 +28,8 @@ type UserItem struct {
}
func NewUserItem(users []string) *UserItem {
warnUserOnNonLinux.Check()
warnUserOnCGODisabled.Check()
userMap := make(map[string]bool)
for _, protocol := range users {
userMap[protocol] = true