platform: Fixes and improvements

This commit is contained in:
世界
2023-04-05 04:38:56 +08:00
parent 28aa4c4d1f
commit 8b64446274
16 changed files with 33 additions and 31 deletions

View File

@@ -1,9 +1,9 @@
//go:build linux || darwin
package libbox
import (
"bytes"
"context"
"encoding/json"
"github.com/sagernet/sing-box"
"github.com/sagernet/sing-box/option"
@@ -35,3 +35,19 @@ func CheckConfig(configContent string) error {
}
return err
}
func FormatConfig(configContent string) (string, error) {
options, err := parseConfig(configContent)
if err != nil {
return "", err
}
var buffer bytes.Buffer
json.NewEncoder(&buffer)
encoder := json.NewEncoder(&buffer)
encoder.SetIndent("", " ")
err = encoder.Encode(options)
if err != nil {
return "", err
}
return buffer.String(), nil
}