new: add tunnel service

This commit is contained in:
Hiddify
2024-01-29 21:55:01 +01:00
parent 25d5b8a1c5
commit 5fa28220b4
28 changed files with 364 additions and 231 deletions

View File

@@ -12,15 +12,29 @@ import (
)
func SaveCurrentConfig(path string, options option.Options) error {
var buffer bytes.Buffer
json.NewEncoder(&buffer)
encoder := json.NewEncoder(&buffer)
encoder.SetIndent("", " ")
err := encoder.Encode(options)
json, err := ToJson(options)
if err != nil {
return err
}
return os.WriteFile(filepath.Join(path, "current-config.json"), buffer.Bytes(), 0777)
p, err := filepath.Abs(filepath.Join(path, "current-config.json"))
fmt.Printf("Saving config to %v %+v\n", p, err)
if err != nil {
return err
}
return os.WriteFile(p, []byte(json), 0644)
}
func ToJson(options option.Options) (string, error) {
var buffer bytes.Buffer
encoder := json.NewEncoder(&buffer)
encoder.SetIndent("", " ")
// fmt.Printf("%+v\n", options)
err := encoder.Encode(options)
if err != nil {
fmt.Printf("ERROR in coding:%+v\n", err)
return "", err
}
return buffer.String(), nil
}
func DeferPanicToError(name string, err func(error)) {