options.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. NTP *NTPOptions `json:"ntp,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. }
  18. type Options _Options
  19. func (o *Options) UnmarshalJSONContext(ctx context.Context, content []byte) error {
  20. decoder := json.NewDecoderContext(ctx, bytes.NewReader(content))
  21. decoder.DisallowUnknownFields()
  22. err := decoder.Decode((*_Options)(o))
  23. if err != nil {
  24. return err
  25. }
  26. o.RawMessage = content
  27. return nil
  28. }
  29. type LogOptions struct {
  30. Disabled bool `json:"disabled,omitempty"`
  31. Level string `json:"level,omitempty"`
  32. Output string `json:"output,omitempty"`
  33. Timestamp bool `json:"timestamp,omitempty"`
  34. DisableColor bool `json:"-"`
  35. }
  36. type StubOptions struct{}