options.go 1.3 KB

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