forked from go/golangs_learn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
548 B
32 lines
548 B
3 years ago
|
package datacache
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"io/ioutil"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
func SavetoJson(data interface{} , path string) error {
|
||
|
string , err := json.Marshal(data)
|
||
|
if err != nil{
|
||
|
return err
|
||
|
}
|
||
|
err = ioutil.WriteFile(path , string , os.ModePerm)
|
||
|
if err != nil{
|
||
|
return err
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func GettoJson(path string , structs interface{}) (error , interface{}) {
|
||
|
data , err := ioutil.ReadFile(path)
|
||
|
if err != nil{
|
||
|
return err , structs
|
||
|
}
|
||
|
err = json.Unmarshal(data , structs)
|
||
|
if err != nil{
|
||
|
return err , structs
|
||
|
}
|
||
|
return nil , structs
|
||
|
}
|