mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-27 09:15:15 +00:00
38 lines
508 B
Go
38 lines
508 B
Go
package util
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
func WriteJsonFile(p string, obj interface{}) error {
|
|
out, err := json.Marshal(obj)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return os.WriteFile(p, out, 0644)
|
|
}
|
|
|
|
func ReadJsonFile(file string, obj interface{}) error {
|
|
f, err := os.Open(file)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
byteResult, err := io.ReadAll(f)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = json.Unmarshal([]byte(byteResult), obj)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|