github.com/inazumav/sing-box@v0.0.0-20230926072359-ab51429a14f1/option/config.go (about)

     1  package option
     2  
     3  import (
     4  	"bytes"
     5  	"strings"
     6  
     7  	"github.com/inazumav/sing-box/common/json"
     8  	E "github.com/sagernet/sing/common/exceptions"
     9  )
    10  
    11  type _Options struct {
    12  	Schema       string               `json:"$schema,omitempty"`
    13  	Log          *LogOptions          `json:"log,omitempty"`
    14  	DNS          *DNSOptions          `json:"dns,omitempty"`
    15  	NTP          *NTPOptions          `json:"ntp,omitempty"`
    16  	Inbounds     []Inbound            `json:"inbounds,omitempty"`
    17  	Outbounds    []Outbound           `json:"outbounds,omitempty"`
    18  	Route        *RouteOptions        `json:"route,omitempty"`
    19  	Experimental *ExperimentalOptions `json:"experimental,omitempty"`
    20  }
    21  
    22  type Options _Options
    23  
    24  func (o *Options) UnmarshalJSON(content []byte) error {
    25  	decoder := json.NewDecoder(json.NewCommentFilter(bytes.NewReader(content)))
    26  	decoder.DisallowUnknownFields()
    27  	err := decoder.Decode((*_Options)(o))
    28  	if err == nil {
    29  		return nil
    30  	}
    31  	if syntaxError, isSyntaxError := err.(*json.SyntaxError); isSyntaxError {
    32  		prefix := string(content[:syntaxError.Offset])
    33  		row := strings.Count(prefix, "\n") + 1
    34  		column := len(prefix) - strings.LastIndex(prefix, "\n") - 1
    35  		return E.Extend(syntaxError, "row ", row, ", column ", column)
    36  	}
    37  	return err
    38  }
    39  
    40  type LogOptions struct {
    41  	Disabled     bool   `json:"disabled,omitempty"`
    42  	Level        string `json:"level,omitempty"`
    43  	Output       string `json:"output,omitempty"`
    44  	Timestamp    bool   `json:"timestamp,omitempty"`
    45  	DisableColor bool   `json:"-"`
    46  }