OSDN Git Service

add get vote result (#345)
[bytom/vapor.git] / toolbar / vote_reward / config / config.go
1 package config
2
3 import (
4         "bytes"
5         "encoding/json"
6         "io/ioutil"
7         "os"
8
9         "github.com/vapor/toolbar/common"
10 )
11
12 type Config struct {
13         MySQLConfig common.MySQLConfig `json:"mysql"`
14         NodeIP      string             `json:"node_ip"`
15 }
16
17 func ExportConfigFile(configFile string, config *Config) error {
18         buf := new(bytes.Buffer)
19
20         encoder := json.NewEncoder(buf)
21         encoder.SetIndent("", "  ")
22         if err := encoder.Encode(config); err != nil {
23                 return err
24         }
25
26         return ioutil.WriteFile(configFile, buf.Bytes(), 0644)
27 }
28
29 func LoadConfigFile(configFile string, config *Config) error {
30         file, err := os.Open(configFile)
31         if err != nil {
32                 return err
33         }
34         defer file.Close()
35
36         return json.NewDecoder(file).Decode(config)
37 }