MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / WriteJsonToFile

Function WriteJsonToFile

pkg/utils/json.go:14–29  ·  view source on GitHub ↗

WriteJsonToFile write struct to json file

(dst string, data interface{}, std ...bool)

Source from the content-addressed store, hash-verified

12
13// WriteJsonToFile write struct to json file
14func WriteJsonToFile(dst string, data interface{}, std ...bool) bool {
15 str, err := json.MarshalIndent(data, "", " ")
16 if len(std) > 0 && std[0] {
17 str, err = stdjson.MarshalIndent(data, "", " ")
18 }
19 if err != nil {
20 log.Errorf("failed convert Conf to []byte:%s", err.Error())
21 return false
22 }
23 err = os.WriteFile(dst, str, 0777)
24 if err != nil {
25 log.Errorf("failed to write json file:%s", err.Error())
26 return false
27 }
28 return true
29}

Callers 2

InitConfigFunction · 0.92
writeFileFunction · 0.92

Calls 1

ErrorMethod · 0.45

Tested by

no test coverage detected