mirror of
https://github.com/SagerNet/sing-box.git
synced 2026-08-27 03:41:09 +00:00
Preserve comments between formatting
This commit is contained in:
parent
a37fcd59bb
commit
7d13cabb6a
2 changed files with 15 additions and 0 deletions
|
|
@ -38,10 +38,12 @@ func format() error {
|
|||
return err
|
||||
}
|
||||
for _, optionsEntry := range optionsList {
|
||||
comments := optionsEntry.options.Comments()
|
||||
optionsEntry.options, err = badjson.Omitempty(globalCtx, optionsEntry.options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
optionsEntry.options.SetComments(comments)
|
||||
buffer := new(bytes.Buffer)
|
||||
encoder := json.NewEncoder(buffer)
|
||||
encoder.SetIndent("", " ")
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
type _Options struct {
|
||||
RawMessage json.RawMessage `json:"-"`
|
||||
CommentsSet *json.CommentSet `json:"-"`
|
||||
Schema string `json:"$schema,omitempty"`
|
||||
Log *LogOptions `json:"log,omitempty"`
|
||||
DNS *DNSOptions `json:"dns,omitempty"`
|
||||
|
|
@ -28,6 +29,10 @@ type _Options struct {
|
|||
|
||||
type Options _Options
|
||||
|
||||
func (o Options) MarshalJSONContext(ctx context.Context) ([]byte, error) {
|
||||
return json.MarshalContext(ctx, (_Options)(o))
|
||||
}
|
||||
|
||||
func (o *Options) UnmarshalJSONContext(ctx context.Context, content []byte) error {
|
||||
decoder := json.NewDecoderContext(ctx, bytes.NewReader(content))
|
||||
decoder.DisallowUnknownFields()
|
||||
|
|
@ -39,6 +44,14 @@ func (o *Options) UnmarshalJSONContext(ctx context.Context, content []byte) erro
|
|||
return checkOptions(o)
|
||||
}
|
||||
|
||||
func (o Options) Comments() *json.CommentSet {
|
||||
return o.CommentsSet
|
||||
}
|
||||
|
||||
func (o *Options) SetComments(comments *json.CommentSet) {
|
||||
o.CommentsSet = comments
|
||||
}
|
||||
|
||||
type LogOptions struct {
|
||||
Disabled bool `json:"disabled,omitempty"`
|
||||
Level string `json:"level,omitempty"`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue