Files
umbrix-libcore/mobile/mobile.go
problematicconsumer 75e342b6ba Fix minor bugs
2023-09-22 23:25:48 +03:30

35 lines
809 B
Go

package mobile
import (
"encoding/json"
"os"
"github.com/hiddify/libcore/shared"
_ "github.com/sagernet/gomobile/event/key"
"github.com/sagernet/sing-box/option"
)
func Parse(path string, tempPath string, debug bool) error {
return shared.ParseConfig(path, tempPath, debug)
}
func BuildConfig(path string, configOptionsJson string) (string, error) {
fileContent, err := os.ReadFile(path)
if err != nil {
return "", err
}
var options option.Options
err = options.UnmarshalJSON(fileContent)
if err != nil {
return "", err
}
configOptions := &shared.ConfigOptions{}
err = json.Unmarshal([]byte(configOptionsJson), configOptions)
if err != nil {
return "", nil
}
options = shared.BuildConfig(*configOptions, options)
config, err := json.Marshal(options)
return string(config), err
}