fix: config export issue
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/hiddify/hiddify-core/config"
|
"github.com/hiddify/hiddify-core/config"
|
||||||
|
pb "github.com/hiddify/hiddify-core/hiddifyrpc"
|
||||||
|
v2 "github.com/hiddify/hiddify-core/v2"
|
||||||
"github.com/sagernet/sing-box/experimental/libbox"
|
"github.com/sagernet/sing-box/experimental/libbox"
|
||||||
"github.com/sagernet/sing-box/log"
|
"github.com/sagernet/sing-box/log"
|
||||||
"github.com/sagernet/sing-box/option"
|
"github.com/sagernet/sing-box/option"
|
||||||
@@ -32,6 +34,19 @@ var commandBuild = &cobra.Command{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
var generateConfig = &cobra.Command{
|
||||||
|
Use: "gen",
|
||||||
|
Short: "gen configuration",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
conf, err := v2.GenerateConfig(&pb.GenerateConfigRequest{
|
||||||
|
Path: args[0],
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
log.Debug(string(conf.ConfigContent))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
var commandCheck = &cobra.Command{
|
var commandCheck = &cobra.Command{
|
||||||
Use: "check",
|
Use: "check",
|
||||||
@@ -49,6 +64,7 @@ func init() {
|
|||||||
addHConfigFlags(commandBuild)
|
addHConfigFlags(commandBuild)
|
||||||
|
|
||||||
mainCommand.AddCommand(commandBuild)
|
mainCommand.AddCommand(commandBuild)
|
||||||
|
mainCommand.AddCommand(generateConfig)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ func ParseConfigContent(contentstr string, debug bool, configOpt *ConfigOptions,
|
|||||||
}
|
}
|
||||||
|
|
||||||
newContent, _ := json.MarshalIndent(jsonObj, "", " ")
|
newContent, _ := json.MarshalIndent(jsonObj, "", " ")
|
||||||
|
|
||||||
return patchConfig(newContent, "SingboxParser", configOpt)
|
return patchConfig(newContent, "SingboxParser", configOpt)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,6 +114,7 @@ func patchConfig(content []byte, name string, configOpt *ConfigOptions) ([]byte,
|
|||||||
}
|
}
|
||||||
|
|
||||||
content, _ = json.MarshalIndent(options, "", " ")
|
content, _ = json.MarshalIndent(options, "", " ")
|
||||||
|
|
||||||
fmt.Printf("%s\n", content)
|
fmt.Printf("%s\n", content)
|
||||||
return validateResult(content, name)
|
return validateResult(content, name)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,10 +56,15 @@ func changeConfigOptions(configOptionsJson *C.char) (CErr *C.char) {
|
|||||||
|
|
||||||
//export generateConfig
|
//export generateConfig
|
||||||
func generateConfig(path *C.char) (res *C.char) {
|
func generateConfig(path *C.char) (res *C.char) {
|
||||||
_, err := v2.GenerateConfig(&pb.GenerateConfigRequest{
|
conf, err := v2.GenerateConfig(&pb.GenerateConfigRequest{
|
||||||
Path: C.GoString(path),
|
Path: C.GoString(path),
|
||||||
})
|
})
|
||||||
return emptyOrErrorC(err)
|
if err != nil {
|
||||||
|
return emptyOrErrorC(err)
|
||||||
|
}
|
||||||
|
fmt.Printf("Config: %+v\n", conf)
|
||||||
|
fmt.Printf("ConfigContent: %+v\n", conf.ConfigContent)
|
||||||
|
return C.CString(conf.ConfigContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export start
|
//export start
|
||||||
|
|||||||
@@ -229,7 +229,9 @@ func GenerateConfig(in *pb.GenerateConfigRequest) (*pb.GenerateConfigResponse, e
|
|||||||
Log(pb.LogLevel_FATAL, pb.LogType_CONFIG, err.Error())
|
Log(pb.LogLevel_FATAL, pb.LogType_CONFIG, err.Error())
|
||||||
StopAndAlert(pb.MessageType_UNEXPECTED_ERROR, err.Error())
|
StopAndAlert(pb.MessageType_UNEXPECTED_ERROR, err.Error())
|
||||||
})
|
})
|
||||||
|
if configOptions == nil {
|
||||||
|
configOptions = config.DefaultConfigOptions()
|
||||||
|
}
|
||||||
config, err := generateConfigFromFile(in.Path, *configOptions)
|
config, err := generateConfigFromFile(in.Path, *configOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in New Issue
Block a user