sing-box/constant/network.go

59 lines
1.2 KiB
Go
Raw Permalink Normal View History

2024-11-11 16:23:45 +08:00
package constant
2024-11-12 19:37:10 +08:00
import (
"github.com/sagernet/sing/common"
F "github.com/sagernet/sing/common/format"
)
2024-11-13 19:05:28 +08:00
type InterfaceType uint8
2024-11-11 16:23:45 +08:00
const (
2024-11-13 19:05:28 +08:00
InterfaceTypeWIFI InterfaceType = iota
InterfaceTypeCellular
InterfaceTypeEthernet
InterfaceTypeOther
)
var (
interfaceTypeToString = map[InterfaceType]string{
InterfaceTypeWIFI: "wifi",
InterfaceTypeCellular: "cellular",
InterfaceTypeEthernet: "ethernet",
InterfaceTypeOther: "other",
}
StringToInterfaceType = common.ReverseMap(interfaceTypeToString)
2024-11-11 16:23:45 +08:00
)
2024-11-12 19:37:10 +08:00
2024-11-13 19:05:28 +08:00
func (t InterfaceType) String() string {
name, loaded := interfaceTypeToString[t]
if !loaded {
return F.ToString(int(t))
}
return name
}
type NetworkStrategy uint8
2024-11-12 19:37:10 +08:00
const (
NetworkStrategyDefault NetworkStrategy = iota
NetworkStrategyFallback
NetworkStrategyHybrid
)
var (
2024-11-13 19:05:28 +08:00
networkStrategyToString = map[NetworkStrategy]string{
NetworkStrategyDefault: "default",
NetworkStrategyFallback: "fallback",
NetworkStrategyHybrid: "hybrid",
2024-11-12 19:37:10 +08:00
}
2024-11-13 19:05:28 +08:00
StringToNetworkStrategy = common.ReverseMap(networkStrategyToString)
2024-11-12 19:37:10 +08:00
)
func (s NetworkStrategy) String() string {
2024-11-13 19:05:28 +08:00
name, loaded := networkStrategyToString[s]
2024-11-12 19:37:10 +08:00
if !loaded {
return F.ToString(int(s))
}
return name
}