bootstrap

This commit is contained in:
problematicconsumer
2023-08-16 15:16:02 +03:30
parent e250a17491
commit d0fe323068
10 changed files with 699 additions and 0 deletions

38
shared/converter.go Normal file
View File

@@ -0,0 +1,38 @@
package shared
import (
_ "embed"
"fmt"
"os"
"github.com/xmdhs/clash2singbox/convert"
"github.com/xmdhs/clash2singbox/model/clash"
"gopkg.in/yaml.v3"
)
func ConvertToSingbox(path string, options ConfigTemplateOptions) ([]byte, error) {
clashConfig := clash.Clash{}
fileContent, err := os.ReadFile(path)
if err != nil {
return nil, err
}
err = yaml.Unmarshal(fileContent, &clashConfig)
if err != nil {
fmt.Printf("unmarshal error %s", err)
return nil, err
}
sbConfig, err := convert.Clash2sing(clashConfig)
if err != nil {
fmt.Printf("convert error %s", err)
return nil, err
}
output := defaultTemplate(options)
output, err = convert.Patch(output, sbConfig, "", "", nil)
if err != nil {
fmt.Printf("patch error %s", err)
return output, err
}
return output, nil
}