Reformat code

This commit is contained in:
世界
2026-08-30 17:41:46 +08:00
parent e4ec3b0345
commit ba4146ea31
30 changed files with 65 additions and 55 deletions
+1 -2
View File
@@ -56,8 +56,7 @@ lint_install:
proto:
@go run ./cmd/internal/protogen
@gofumpt -l -w .
@gofumpt -l -w .
@golangci-lint fmt
proto_install:
go install -v google.golang.org/protobuf/cmd/protoc-gen-go@latest
+1 -1
View File
@@ -29,7 +29,7 @@ type RawHalfConn struct {
func NewRawHalfConn(rawHalfConn reflect.Value, methods *Methods) (*RawHalfConn, error) {
halfConn := &RawHalfConn{
pointer: (unsafe.Pointer)(rawHalfConn.UnsafeAddr()),
pointer: unsafe.Pointer(rawHalfConn.UnsafeAddr()),
methods: methods,
}
+1 -1
View File
@@ -243,7 +243,7 @@ var (
file_daemon_managed_service_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
file_daemon_managed_service_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
file_daemon_managed_service_proto_goTypes = []any{
(DebugCrashRequest_Type)(0), // 0: daemon.DebugCrashRequest.Type
DebugCrashRequest_Type(0), // 0: daemon.DebugCrashRequest.Type
(*SystemProxyStatus)(nil), // 1: daemon.SystemProxyStatus
(*SetSystemProxyEnabledRequest)(nil), // 2: daemon.SetSystemProxyEnabledRequest
(*DebugCrashRequest)(nil), // 3: daemon.DebugCrashRequest
+5 -5
View File
@@ -7972,11 +7972,11 @@ var (
file_daemon_started_service_proto_enumTypes = make([]protoimpl.EnumInfo, 5)
file_daemon_started_service_proto_msgTypes = make([]protoimpl.MessageInfo, 102)
file_daemon_started_service_proto_goTypes = []any{
(LogLevel)(0), // 0: daemon.LogLevel
(ConnectionEventType)(0), // 1: daemon.ConnectionEventType
(USBDeviceState)(0), // 2: daemon.USBDeviceState
(USBBackend)(0), // 3: daemon.USBBackend
(ServiceStatus_Type)(0), // 4: daemon.ServiceStatus.Type
LogLevel(0), // 0: daemon.LogLevel
ConnectionEventType(0), // 1: daemon.ConnectionEventType
USBDeviceState(0), // 2: daemon.USBDeviceState
USBBackend(0), // 3: daemon.USBBackend
ServiceStatus_Type(0), // 4: daemon.ServiceStatus.Type
(*Version)(nil), // 5: daemon.Version
(*ServiceStatus)(nil), // 6: daemon.ServiceStatus
(*SubscribeStatusRequest)(nil), // 7: daemon.SubscribeStatusRequest
+4 -3
View File
@@ -6,6 +6,7 @@ import (
unsafe "unsafe"
daemon "github.com/sagernet/sing-box/daemon"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
emptypb "google.golang.org/protobuf/types/known/emptypb"
@@ -1816,9 +1817,9 @@ var (
file_experimental_boxdd_desktop_service_proto_enumTypes = make([]protoimpl.EnumInfo, 3)
file_experimental_boxdd_desktop_service_proto_msgTypes = make([]protoimpl.MessageInfo, 28)
file_experimental_boxdd_desktop_service_proto_goTypes = []any{
(DaemonOwnership)(0), // 0: desktop.DaemonOwnership
(InstallUpdateResult)(0), // 1: desktop.InstallUpdateResult
(ProfileContent_Type)(0), // 2: desktop.ProfileContent.Type
DaemonOwnership(0), // 0: desktop.DaemonOwnership
InstallUpdateResult(0), // 1: desktop.InstallUpdateResult
ProfileContent_Type(0), // 2: desktop.ProfileContent.Type
(*ArchiveReportRequest)(nil), // 3: desktop.ArchiveReportRequest
(*StandaloneNetworkQualityTestRequest)(nil), // 4: desktop.StandaloneNetworkQualityTestRequest
(*StandaloneSTUNTestRequest)(nil), // 5: desktop.StandaloneSTUNTestRequest
@@ -4,6 +4,7 @@ import (
context "context"
daemon "github.com/sagernet/sing-box/daemon"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
+1 -1
View File
@@ -207,7 +207,7 @@ func (c *CacheFile) start() error {
if name[0] == 0 {
return b.ForEachBucket(func(k []byte) error {
bucketName := string(k)
if !(common.Contains(bucketNameList, bucketName)) {
if !common.Contains(bucketNameList, bucketName) {
_ = b.DeleteBucket(name)
}
return nil
+1 -1
View File
@@ -181,7 +181,7 @@ func (w *platformInterfaceWrapper) ReadWIFIState(ctx context.Context) adapter.WI
if wifiState == nil {
return adapter.WIFIState{}
}
return (adapter.WIFIState)(*wifiState)
return adapter.WIFIState(*wifiState)
}
func (w *platformInterfaceWrapper) UsePlatformConnectionOwnerFinder() bool {
+1 -1
View File
@@ -62,7 +62,7 @@ func (o ACMEProviderDNS01ChallengeOptions) MarshalJSON() ([]byte, error) {
default:
return nil, E.New("unknown provider type: ", o.Provider)
}
return badjson.MarshallObjects((_ACMEProviderDNS01ChallengeOptions)(o), v)
return badjson.MarshallObjects(_ACMEProviderDNS01ChallengeOptions(o), v)
}
func (o *ACMEProviderDNS01ChallengeOptions) UnmarshalJSON(bytes []byte) error {
+1 -1
View File
@@ -81,7 +81,7 @@ func (o OptimisticDNSOptions) MarshalJSON() ([]byte, error) {
if o.Timeout == 0 {
return json.Marshal(o.Enabled)
}
return json.Marshal((_OptimisticDNSOptions)(o))
return json.Marshal(_OptimisticDNSOptions(o))
}
func (o *OptimisticDNSOptions) UnmarshalJSON(bytes []byte) error {
+3 -3
View File
@@ -71,9 +71,9 @@ func (o Hysteria2Obfs) MarshalJSON() ([]byte, error) {
return nil, E.New("unknown obfs type: ", o.Type)
}
if v == nil {
return json.Marshal((_Hysteria2Obfs)(o))
return json.Marshal(_Hysteria2Obfs(o))
}
return badjson.MarshallObjects((_Hysteria2Obfs)(o), v)
return badjson.MarshallObjects(_Hysteria2Obfs(o), v)
}
func (o *Hysteria2Obfs) UnmarshalJSON(bytes []byte) error {
@@ -131,7 +131,7 @@ func (m Hysteria2Masquerade) MarshalJSON() ([]byte, error) {
default:
return nil, E.New("unknown masquerade type: ", m.Type)
}
return badjson.MarshallObjects((_Hysteria2Masquerade)(m), v)
return badjson.MarshallObjects(_Hysteria2Masquerade(m), v)
}
func (m *Hysteria2Masquerade) UnmarshalJSON(bytes []byte) error {
+1 -1
View File
@@ -151,7 +151,7 @@ func (b UDPNATBehavior) DescribeSchema(builder schema.Builder) (*schema.Node, er
type UDPTimeoutCompat badoption.Duration
func (c UDPTimeoutCompat) MarshalJSON() ([]byte, error) {
return json.Marshal((time.Duration)(c).String())
return json.Marshal(time.Duration(c).String())
}
func (c *UDPTimeoutCompat) UnmarshalJSON(data []byte) error {
+1 -1
View File
@@ -30,7 +30,7 @@ func (o NetworkNamespace) MarshalJSON() ([]byte, error) {
default:
return nil, E.New("unknown network namespace type: ", o.Type)
}
return badjson.MarshallObjects((_NetworkNamespace)(o), v)
return badjson.MarshallObjects(_NetworkNamespace(o), v)
}
func (o *NetworkNamespace) UnmarshalJSON(content []byte) error {
+1 -1
View File
@@ -33,7 +33,7 @@ type _Options struct {
type Options _Options
func (o Options) MarshalJSONContext(ctx context.Context) ([]byte, error) {
return json.MarshalContext(ctx, (_Options)(o))
return json.MarshalContext(ctx, _Options(o))
}
func (o *Options) UnmarshalJSONContext(ctx context.Context, content []byte) error {
+1 -1
View File
@@ -134,7 +134,7 @@ func (o DomainResolveOptions) MarshalJSON() ([]byte, error) {
o.ClientSubnet == nil {
return json.Marshal(o.Server)
} else {
return json.Marshal((_DomainResolveOptions)(o))
return json.Marshal(_DomainResolveOptions(o))
}
}
+1 -1
View File
@@ -18,7 +18,7 @@ type _ResolvedServiceOptions struct {
type ResolvedServiceOptions _ResolvedServiceOptions
func (r ResolvedServiceOptions) MarshalJSONContext(ctx context.Context) ([]byte, error) {
if r.Listen != nil && netip.Addr(*r.Listen) == (netip.AddrFrom4([4]byte{127, 0, 0, 53})) {
if r.Listen != nil && netip.Addr(*r.Listen) == netip.AddrFrom4([4]byte{127, 0, 0, 53}) {
r.Listen = nil
}
if r.ListenPort == 53 {
+1 -1
View File
@@ -32,7 +32,7 @@ func (r Rule) MarshalJSON() ([]byte, error) {
default:
return nil, E.New("unknown rule type: " + r.Type)
}
return badjson.MarshallObjects((_Rule)(r), v)
return badjson.MarshallObjects(_Rule(r), v)
}
func (r *Rule) UnmarshalJSONContext(ctx context.Context, bytes []byte) error {
+5 -5
View File
@@ -55,9 +55,9 @@ func (r RuleAction) MarshalJSON() ([]byte, error) {
return nil, E.New("unknown rule action: " + r.Action)
}
if v == nil {
return badjson.MarshallObjects((_RuleAction)(r))
return badjson.MarshallObjects(_RuleAction(r))
}
return badjson.MarshallObjects((_RuleAction)(r), v)
return badjson.MarshallObjects(_RuleAction(r), v)
}
func (r *RuleAction) UnmarshalJSON(data []byte) error {
@@ -133,9 +133,9 @@ func (r DNSRuleAction) MarshalJSON() ([]byte, error) {
return nil, E.New("unknown DNS rule action: " + r.Action)
}
if v == nil {
return badjson.MarshallObjects((_DNSRuleAction)(r))
return badjson.MarshallObjects(_DNSRuleAction(r))
}
return badjson.MarshallObjects((_DNSRuleAction)(r), v)
return badjson.MarshallObjects(_DNSRuleAction(r), v)
}
func (r *DNSRuleAction) UnmarshalJSONContext(ctx context.Context, data []byte) error {
@@ -300,7 +300,7 @@ func (r RejectActionOptions) MarshalJSON() ([]byte, error) {
case C.RuleActionRejectMethodDefault:
r.Method = ""
}
return json.Marshal((_RejectActionOptions)(r))
return json.Marshal(_RejectActionOptions(r))
}
func (r *RejectActionOptions) UnmarshalJSON(bytes []byte) error {
+1 -1
View File
@@ -32,7 +32,7 @@ func (r DNSRule) MarshalJSON() ([]byte, error) {
default:
return nil, E.New("unknown rule type: " + r.Type)
}
return badjson.MarshallObjects((_DNSRule)(r), v)
return badjson.MarshallObjects(_DNSRule(r), v)
}
func (r *DNSRule) UnmarshalJSONContext(ctx context.Context, bytes []byte) error {
+3 -3
View File
@@ -55,7 +55,7 @@ func (r RuleSet) MarshalJSON() ([]byte, error) {
default:
return nil, E.New("unknown rule-set type: " + r.Type)
}
return badjson.MarshallObjects((_RuleSet)(r), v)
return badjson.MarshallObjects(_RuleSet(r), v)
}
func (r *RuleSet) UnmarshalJSON(bytes []byte) error {
@@ -206,7 +206,7 @@ func (r HeadlessRule) MarshalJSON() ([]byte, error) {
default:
return nil, E.New("unknown rule type: " + r.Type)
}
return badjson.MarshallObjects((_HeadlessRule)(r), v)
return badjson.MarshallObjects(_HeadlessRule(r), v)
}
func (r *HeadlessRule) UnmarshalJSON(bytes []byte) error {
@@ -316,7 +316,7 @@ func (r PlainRuleSetCompat) MarshalJSON() ([]byte, error) {
default:
return nil, E.New("unknown rule-set version: ", r.Version)
}
return badjson.MarshallObjects((_PlainRuleSetCompat)(r), v)
return badjson.MarshallObjects(_PlainRuleSetCompat(r), v)
}
func (r *PlainRuleSetCompat) UnmarshalJSON(bytes []byte) error {
+2 -2
View File
@@ -55,7 +55,7 @@ func (o SnellInboundOptions) MarshalJSON() ([]byte, error) {
default:
return nil, E.New("snell: unsupported version: ", o.Version)
}
return badjson.MarshallObjects((_SnellInboundOptions)(o), versionOptions)
return badjson.MarshallObjects(_SnellInboundOptions(o), versionOptions)
}
func (o SnellInboundOptions) DescribeSchema(builder schema.Builder) (*schema.Node, error) {
@@ -116,7 +116,7 @@ func (o SnellOutboundOptions) MarshalJSON() ([]byte, error) {
default:
return nil, E.New("snell: unsupported version: ", o.Version)
}
return badjson.MarshallObjects((_SnellOutboundOptions)(o), versionOptions)
return badjson.MarshallObjects(_SnellOutboundOptions(o), versionOptions)
}
func (o SnellOutboundOptions) DescribeSchema(builder schema.Builder) (*schema.Node, error) {
+1 -1
View File
@@ -54,7 +54,7 @@ func (o ACMEDNS01ChallengeOptions) MarshalJSON() ([]byte, error) {
default:
return nil, E.New("unknown provider type: " + o.Provider)
}
return badjson.MarshallObjects((_ACMEDNS01ChallengeOptions)(o), v)
return badjson.MarshallObjects(_ACMEDNS01ChallengeOptions(o), v)
}
func (o *ACMEDNS01ChallengeOptions) UnmarshalJSON(bytes []byte) error {
+2 -2
View File
@@ -24,9 +24,9 @@ type USBIPServerServiceOptions _USBIPServerServiceOptions
func (o USBIPServerServiceOptions) MarshalJSON() ([]byte, error) {
if o.Options == nil {
return json.Marshal((_USBIPServerServiceOptions)(o))
return json.Marshal(_USBIPServerServiceOptions(o))
}
return badjson.MarshallObjects((_USBIPServerServiceOptions)(o), o.Options)
return badjson.MarshallObjects(_USBIPServerServiceOptions(o), o.Options)
}
func (o *USBIPServerServiceOptions) UnmarshalJSON(content []byte) error {
+1 -1
View File
@@ -40,7 +40,7 @@ func (o V2RayTransportOptions) MarshalJSON() ([]byte, error) {
default:
return nil, E.New("unknown transport type: " + o.Type)
}
return badjson.MarshallObjects((_V2RayTransportOptions)(o), v)
return badjson.MarshallObjects(_V2RayTransportOptions(o), v)
}
func (o *V2RayTransportOptions) UnmarshalJSON(bytes []byte) error {
+1 -1
View File
@@ -59,7 +59,7 @@ func NewInbound(ctx context.Context, router adapter.Router, logger log.ContextLo
service, err := anytls.NewService(anytls.ServiceConfig{
Users: common.Map(options.Users, func(it option.AnyTLSUser) anytls.User {
return (anytls.User)(it)
return anytls.User(it)
}),
PaddingScheme: paddingScheme,
Handler: (*inboundHandler)(inbound),
+1 -1
View File
@@ -100,7 +100,7 @@ func (h *Outbound) Start(stage adapter.StartStage) error {
h.client = client
h.sessionClient = sessionClientOf(client)
h.uotClient = &uot.Client{
Dialer: (anytlsDialer)(h.createProxy),
Dialer: anytlsDialer(h.createProxy),
Version: uot.Version,
}
return nil
+1 -1
View File
@@ -71,7 +71,7 @@ func NewInbound(ctx context.Context, router adapter.Router, logger log.ContextLo
Version: options.Version,
Password: options.Password,
Users: common.Map(options.Users, func(it option.ShadowTLSUser) shadowtls.User {
return (shadowtls.User)(it)
return shadowtls.User(it)
}),
Handshake: shadowtls.HandshakeConfig{
Server: options.Handshake.ServerOptions.Build(),
+1 -1
View File
@@ -14,7 +14,7 @@ import (
var (
_ tun.FlowTracker = (*flowLogger)(nil)
_ tun.FlowTracker = (multiFlowTracker)(nil)
_ tun.FlowTracker = multiFlowTracker(nil)
)
type flowLogger struct {
+17 -8
View File
@@ -57,12 +57,18 @@ type countingRuleSet struct {
refs atomic.Int32
}
func (s *countingRuleSet) Name() string { return s.name }
func (s *countingRuleSet) Name() string { return s.name }
func (s *countingRuleSet) StartContext(context.Context, *adapter.HTTPStartContext) error { return nil }
func (s *countingRuleSet) PostStart() error { return nil }
func (s *countingRuleSet) Metadata() adapter.RuleSetMetadata { return adapter.RuleSetMetadata{} }
func (s *countingRuleSet) ExtractIPSet() []*netipx.IPSet { return nil }
func (s *countingRuleSet) IncRef() { s.refs.Add(1) }
func (s *countingRuleSet) PostStart() error { return nil }
func (s *countingRuleSet) Metadata() adapter.RuleSetMetadata { return adapter.RuleSetMetadata{} }
func (s *countingRuleSet) ExtractIPSet() []*netipx.IPSet { return nil }
func (s *countingRuleSet) IncRef() { s.refs.Add(1) }
func (s *countingRuleSet) DecRef() {
if s.refs.Add(-1) < 0 {
panic("rule-set: negative refs")
@@ -74,9 +80,12 @@ func (s *countingRuleSet) RegisterCallback(adapter.RuleSetUpdateCallback) *list.
}
func (s *countingRuleSet) UnregisterCallback(*list.Element[adapter.RuleSetUpdateCallback]) {}
func (s *countingRuleSet) Close() error { return nil }
func (s *countingRuleSet) Match(*adapter.InboundContext) bool { return true }
func (s *countingRuleSet) String() string { return s.name }
func (s *countingRuleSet) RefCount() int32 { return s.refs.Load() }
func (s *countingRuleSet) Match(*adapter.InboundContext) bool { return true }
func (s *countingRuleSet) String() string { return s.name }
func (s *countingRuleSet) RefCount() int32 { return s.refs.Load() }
func TestRuleSetItemCloseReleasesRefs(t *testing.T) {
t.Parallel()
+3 -3
View File
@@ -250,16 +250,16 @@ func (e remoteEndpoint) SrcToString() string {
}
func (e remoteEndpoint) DstToString() string {
return (netip.AddrPort)(e).String()
return netip.AddrPort(e).String()
}
func (e remoteEndpoint) DstToBytes() []byte {
b, _ := (netip.AddrPort)(e).MarshalBinary()
b, _ := netip.AddrPort(e).MarshalBinary()
return b
}
func (e remoteEndpoint) DstIP() netip.Addr {
return (netip.AddrPort)(e).Addr()
return netip.AddrPort(e).Addr()
}
func (e remoteEndpoint) SrcIP() netip.Addr {