chore: sub-store Go 重写项目初始化
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package render
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/peterqiu0516/sub-store/internal/model"
|
||||
)
|
||||
|
||||
// RenderJson renders proxies as a raw JSON object: {"proxies": [...]}.
|
||||
func RenderJson(proxies []model.ProxyNode) string {
|
||||
// Convert each ProxyNode (map[string]any) to a clean map with nil values removed
|
||||
cleaned := make([]any, 0, len(proxies))
|
||||
for _, p := range proxies {
|
||||
cleaned = append(cleaned, stripNil(p))
|
||||
}
|
||||
doc := map[string]any{"proxies": cleaned}
|
||||
data, _ := json.MarshalIndent(doc, "", " ")
|
||||
return string(data)
|
||||
}
|
||||
|
||||
// stripNil removes nil values from a map recursively (shallow).
|
||||
func stripNil(m map[string]any) map[string]any {
|
||||
result := make(map[string]any, len(m))
|
||||
for k, v := range m {
|
||||
if v == nil {
|
||||
continue
|
||||
}
|
||||
result[k] = v
|
||||
}
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user