tcp server 用于给andriod 客户端定时发送消息
fix
liuxiaolong
2019-11-01 609cde4c5f1f125461578b2cc0c1f098c1ae2a1a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package config
 
import (
    "github.com/spf13/viper"
    "log"
)
 
type server []ServerInfo
 
type ServerInfo struct {
    ServerId string `mapstructure: "serverId"`
    ServerIp string `mapstructure: "serverIp"`
    VideoPort string   `mapstructure: "videoPort"`
    NginxIp string  `mapstructure: "ngxIp"`
    NginxPort string   `mapstructure: "ngxPort"`
}
 
var serverList = &server{}
 
var ServerMap = make(map[string]string,0)
var NgxMap = make(map[string]string,0)
func Init(env string) {
    var err error
    viper.SetConfigType("yaml")
    viper.SetConfigName(env)
    viper.AddConfigPath("./config/")
    err = viper.ReadInConfig()
    if err != nil {
        log.Fatal("error on parsing configuration file")
    }
    viper.UnmarshalKey("server", serverList)
    for _,s :=range *serverList {
        ServerMap[s.ServerId] = "http://"+s.ServerIp+":"+s.VideoPort+"/getRecordVideoPath"
        NgxMap[s.ServerId] = "http://"+s.NginxIp+":"+s.NginxPort+"/videosource"
    }
}