OSDN Git Service

fix the bug (#372)
[bytom/vapor.git] / config / federation.go
1 package config
2
3 import (
4         "bytes"
5         "encoding/json"
6         "io/ioutil"
7         "os"
8 )
9
10 func ExportFederationFile(fedFile string, config *Config) error {
11         buf := new(bytes.Buffer)
12
13         encoder := json.NewEncoder(buf)
14         encoder.SetIndent("", "  ")
15         if err := encoder.Encode(config.Federation); err != nil {
16                 return err
17         }
18
19         return ioutil.WriteFile(fedFile, buf.Bytes(), 0644)
20 }
21
22 func LoadFederationFile(fedFile string, config *Config) error {
23         file, err := os.Open(fedFile)
24         if err != nil {
25                 return err
26         }
27         defer file.Close()
28
29         return json.NewDecoder(file).Decode(config.Federation)
30 }