refactor to compatible with sing-box 1.11

This commit is contained in:
2025-01-20 15:08:49 +08:00
parent 22ae18120a
commit 0a6fe9da0c
13 changed files with 340 additions and 169 deletions

58
model/options.go Normal file
View File

@@ -0,0 +1,58 @@
package model
import (
"bytes"
"context"
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing/common/json"
"github.com/sagernet/sing/common/json/badjson"
)
type _Options struct {
option.Options
Endpoints []Endpoint `json:"endpoints,omitempty"`
Inbounds []Inbound `json:"inbounds,omitempty"`
Outbounds []Outbound `json:"outbounds,omitempty"`
}
type Options _Options
func (o *Options) UnmarshalJSONContext(ctx context.Context, content []byte) error {
decoder := json.NewDecoderContext(ctx, bytes.NewReader(content))
decoder.DisallowUnknownFields()
err := decoder.Decode((*_Options)(o))
if err != nil {
return err
}
o.RawMessage = content
return nil
}
type LogOptions struct {
Disabled bool `json:"disabled,omitempty"`
Level string `json:"level,omitempty"`
Output string `json:"output,omitempty"`
Timestamp bool `json:"timestamp,omitempty"`
DisableColor bool `json:"-"`
}
type StubOptions struct{}
type Endpoint option.Endpoint
func (e *Endpoint) MarshalJSON() ([]byte, error) {
return badjson.MarshallObjects((*option.Endpoint)(e), e.Options)
}
type Inbound option.Inbound
func (i *Inbound) MarshalJSON() ([]byte, error) {
return badjson.MarshallObjects((*option.Inbound)(i), i.Options)
}
type Outbound option.Outbound
func (o *Outbound) MarshalJSON() ([]byte, error) {
return badjson.MarshallObjects((*option.Outbound)(o), o.Options)
}