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.
31 lines
548 B
31 lines
548 B
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
|
|
}
|
|
|