options.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. Endpoints []Endpoint `json:"endpoints,omitempty"`
  14. Inbounds []Inbound `json:"inbounds,omitempty"`
  15. Outbounds []Outbound `json:"outbounds,omitempty"`
  16. Route *RouteOptions `json:"route,omitempty"`
  17. Experimental *ExperimentalOptions `json:"experimental,omitempty"`
  18. }
  19. type Options _Options
  20. func (o *Options) UnmarshalJSONContext(ctx context.Context, content []byte) error {
  21. decoder := json.NewDecoderContext(ctx, bytes.NewReader(content))
  22. decoder.DisallowUnknownFields()
  23. err := decoder.Decode((*_Options)(o))
  24. if err != nil {
  25. return err
  26. }
  27. o.RawMessage = content
  28. return nil
  29. }
  30. type LogOptions struct {
  31. Disabled bool `json:"disabled,omitempty"`
  32. Level string `json:"level,omitempty"`
  33. Output string `json:"output,omitempty"`
  34. Timestamp bool `json:"timestamp,omitempty"`
  35. DisableColor bool `json:"-"`
  36. }
  37. type StubOptions struct{}