Add config export

This commit is contained in:
problematicconsumer
2023-11-12 12:50:14 +03:30
parent 5c8b283d9c
commit 953e6a02d7
3 changed files with 44 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
package shared
import (
"bytes"
"encoding/json"
"fmt"
"net"
@@ -38,6 +39,19 @@ type ConfigOptions struct {
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
func BuildConfig(configOpt ConfigOptions, input option.Options) option.Options {
if configOpt.ExecuteAsIs {