Add config export
This commit is contained in:
@@ -80,6 +80,35 @@ func changeConfigOptions(configOptionsJson *C.char) (CErr *C.char) {
|
|||||||
return C.CString("")
|
return C.CString("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//export generateConfig
|
||||||
|
func generateConfig(path *C.char) (res *C.char) {
|
||||||
|
defer shared.DeferPanicToError("generateConfig", func(err error) {
|
||||||
|
res = C.CString("error" + err.Error())
|
||||||
|
})
|
||||||
|
|
||||||
|
config, err := generateConfigFromFile(C.GoString(path), *configOptions)
|
||||||
|
if err != nil {
|
||||||
|
return C.CString("error" + err.Error())
|
||||||
|
}
|
||||||
|
return C.CString(config)
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateConfigFromFile(path string, configOpt shared.ConfigOptions) (string, error) {
|
||||||
|
content, err := os.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
options, err := parseConfig(string(content))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
config, err := shared.BuildConfigJson(configOpt, options)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return config, nil
|
||||||
|
}
|
||||||
|
|
||||||
//export start
|
//export start
|
||||||
func start(configPath *C.char, disableMemoryLimit bool) (CErr *C.char) {
|
func start(configPath *C.char, disableMemoryLimit bool) (CErr *C.char) {
|
||||||
defer shared.DeferPanicToError("start", func(err error) {
|
defer shared.DeferPanicToError("start", func(err error) {
|
||||||
|
|||||||
@@ -28,7 +28,5 @@ func BuildConfig(path string, configOptionsJson string) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
options = shared.BuildConfig(*configOptions, options)
|
return shared.BuildConfigJson(*configOptions, options)
|
||||||
config, err := json.Marshal(options)
|
|
||||||
return string(config), err
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package shared
|
package shared
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
@@ -38,6 +39,19 @@ type ConfigOptions struct {
|
|||||||
Rules []Rule `json:"rules"`
|
Rules []Rule `json:"rules"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BuildConfigJson(configOpt ConfigOptions, input option.Options) (string, error) {
|
||||||
|
options := BuildConfig(configOpt, input)
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
// TODO include selectors
|
// TODO include selectors
|
||||||
func BuildConfig(configOpt ConfigOptions, input option.Options) option.Options {
|
func BuildConfig(configOpt ConfigOptions, input option.Options) option.Options {
|
||||||
if configOpt.ExecuteAsIs {
|
if configOpt.ExecuteAsIs {
|
||||||
|
|||||||
Reference in New Issue
Block a user