options.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package option
  2. import (
  3. "bytes"
  4. "context"
  5. "github.com/sagernet/sing/common/json"
  6. )
  7. type _Options struct {
  8. RawMessage json.RawMessage `json:"-"`
  9. Schema string `json:"$schema,omitempty"`
  10. Log *LogOptions `json:"log,omitempty"`
  11. DNS *DNSOptions `json:"dns,omitempty"`
  12. Endpoints []Endpoint `json:"endpoints,omitempty"`
  13. Inbounds []Inbound `json:"inbounds,omitempty"`
  14. Outbounds []Outbound `json:"outbounds,omitempty"`
  15. Route *RouteOptions `json:"route,omitempty"`
  16. Experimental *ExperimentalOptions `json:"experimental,omitempty"`
  17. NTP *NTPOptions `json:"ntp,omitempty"`
  18. Certificate *CertificateOptions `json:"certificate,omitempty"`
  19. MITM *MITMOptions `json:"mitm,omitempty"`
  20. Scripts []Script `json:"scripts,omitempty"`
  21. }
  22. type Options _Options
  23. func (o *Options) UnmarshalJSONContext(ctx context.Context, content []byte) error {
  24. decoder := json.NewDecoderContext(ctx, bytes.NewReader(content))
  25. decoder.DisallowUnknownFields()
  26. err := decoder.Decode((*_Options)(o))
  27. if err != nil {
  28. return err
  29. }
  30. o.RawMessage = content
  31. return nil
  32. }
  33. type LogOptions struct {
  34. Disabled bool `json:"disabled,omitempty"`
  35. Level string `json:"level,omitempty"`
  36. Output string `json:"output,omitempty"`
  37. Timestamp bool `json:"timestamp,omitempty"`
  38. DisableColor bool `json:"-"`
  39. }
  40. type StubOptions struct{}