diff --git a/main.go b/main.go index a201da3..6872704 100644 --- a/main.go +++ b/main.go @@ -2,37 +2,10 @@ package main import ( "chia_api/data" - "chia_api/redis" "chia_api/server" "flag" - "gopkg.in/yaml.v2" - "io/ioutil" - "log" ) -type Config struct { - RedisHost string `yaml:"host"` - RedisPort int `yaml:"port"` - RedisPassword string `yaml:"password"` - RedisLifetime int `yaml:"lifetime"` -} - -func getConf() { - c := &Config{} - yamlFile, err := ioutil.ReadFile("redis_config.yaml") - if err != nil { - log.Printf("yamlFile.Get err #%v ", err) - } - err = yaml.Unmarshal(yamlFile, c) - if err != nil { - log.Fatalf("Unmarshal: %v", err) - } - redis.Host = c.RedisHost - redis.Password = c.RedisPassword - redis.Port = c.RedisPort - redis.Lifetime = c.RedisLifetime -} - func main() { var bddType string var dbPath string @@ -63,8 +36,7 @@ func main() { data.API_PORT = apiPort data.API_HOST = apiHost + data.Migrate() - //data.Migrate() - //getConf() server.GetServer().Run() } diff --git a/redis/redis.go b/redis/redis.go index 9c21d41..ac2b25c 100644 --- a/redis/redis.go +++ b/redis/redis.go @@ -2,6 +2,9 @@ package redis import ( "fmt" + "gopkg.in/yaml.v2" + "io/ioutil" + "log" "strconv" "time" @@ -9,15 +12,40 @@ import ( ) var ( - Host = "localhost" + Host = "should_never_be_seen" Port = 6379 Password = "" Clis = make(map[int]*redis.Client, 2) Lifetime = 60 ) +type Config struct { + RedisHost string `yaml:"host"` + RedisPort int `yaml:"port"` + RedisPassword string `yaml:"password"` + RedisLifetime int `yaml:"lifetime"` +} + +func getRedisConf() { + c := &Config{} + yamlFile, err := ioutil.ReadFile("redis_config.yaml") + if err != nil { + log.Printf("yamlFile.Get err #%v ", err) + } + err = yaml.Unmarshal(yamlFile, c) + if err != nil { + log.Fatalf("Unmarshal: %v", err) + } + Host = c.RedisHost + Password = c.RedisPassword + Port = c.RedisPort + Lifetime = c.RedisLifetime + fmt.Println(Host, c) +} + func init() { + getRedisConf() connect(0) go func() { for {