sing-box/constant/network.go

59 lines
1.2 KiB
Go
Raw Permalink Normal View History

2024-11-11 08:23:45 +00:00
package constant
2024-11-12 11:37:10 +00:00
import (
"github.com/sagernet/sing/common"
F "github.com/sagernet/sing/common/format"
)
2024-11-13 11:05:28 +00:00
type InterfaceType uint8
2024-11-11 08:23:45 +00:00
const (
2024-11-13 11:05:28 +00: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 08:23:45 +00:00
)
2024-11-12 11:37:10 +00:00
2024-11-13 11:05:28 +00: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 11:37:10 +00:00
const (
NetworkStrategyDefault NetworkStrategy = iota
NetworkStrategyFallback
NetworkStrategyHybrid
)
var (
2024-11-13 11:05:28 +00:00
networkStrategyToString = map[NetworkStrategy]string{
NetworkStrategyDefault: "default",
NetworkStrategyFallback: "fallback",
NetworkStrategyHybrid: "hybrid",
2024-11-12 11:37:10 +00:00
}
2024-11-13 11:05:28 +00:00
StringToNetworkStrategy = common.ReverseMap(networkStrategyToString)
2024-11-12 11:37:10 +00:00
)
func (s NetworkStrategy) String() string {
2024-11-13 11:05:28 +00:00
name, loaded := networkStrategyToString[s]
2024-11-12 11:37:10 +00:00
if !loaded {
return F.ToString(int(s))
}
return name
}