remove jinzhu/configor dependency
This commit is contained in:
parent
f9ebac8a69
commit
d194186353
@ -19,7 +19,6 @@ import (
|
|||||||
|
|
||||||
"github.com/go-log/log"
|
"github.com/go-log/log"
|
||||||
"github.com/go-redis/redis"
|
"github.com/go-redis/redis"
|
||||||
"github.com/jinzhu/configor"
|
|
||||||
"github.com/ginuerzh/gost"
|
"github.com/ginuerzh/gost"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -325,7 +324,7 @@ func (r *route) serve() error {
|
|||||||
if node.User != nil {
|
if node.User != nil {
|
||||||
users = append(users, node.User)
|
users = append(users, node.User)
|
||||||
}
|
}
|
||||||
redisClient, err := parseRedisUsersAuth(node.Values.Get("redis"))
|
redisClient, err := connectToRedis(node.Values.Get("redis"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -611,24 +610,32 @@ func parseUsers(authFile string) (users []*url.Userinfo, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseRedisUsersAuth(configFile string) (client *redis.Client, err error) {
|
type redisConfig struct {
|
||||||
if configFile == "" {
|
Address string `json:"address"`
|
||||||
|
Password string `json:"password"`
|
||||||
|
DB int `json:"db"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func connectToRedis(redisCfg string) (client *redis.Client, err error){
|
||||||
|
if redisCfg == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var Config = struct {
|
content, err := ioutil.ReadFile(redisCfg)
|
||||||
RedisServer struct {
|
if err != nil {
|
||||||
Address string `default:"localhost:6379"`
|
return
|
||||||
Password string `default:""`
|
}
|
||||||
DB int `default:0`
|
|
||||||
|
config := new(redisConfig)
|
||||||
|
err = json.Unmarshal(content, &config)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}{}
|
|
||||||
|
|
||||||
configor.Load(&Config, configFile)
|
|
||||||
client = redis.NewClient(&redis.Options{
|
client = redis.NewClient(&redis.Options{
|
||||||
Addr: Config.RedisServer.Address,
|
Addr: config.Address,
|
||||||
Password: Config.RedisServer.Password,
|
Password: config.Password,
|
||||||
DB: Config.RedisServer.DB,
|
DB: config.DB,
|
||||||
})
|
})
|
||||||
|
|
||||||
_, err = client.Ping().Result()
|
_, err = client.Ping().Result()
|
||||||
@ -636,7 +643,7 @@ func parseRedisUsersAuth(configFile string) (client *redis.Client, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseIP(s string) (ips []string) {
|
func parseIP(s string, port string) (ips []string) {
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
5
cmd/gost/redis.json
Normal file
5
cmd/gost/redis.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"address": "localhost:6379",
|
||||||
|
"password": "",
|
||||||
|
"db": 0
|
||||||
|
}
|
@ -1,5 +0,0 @@
|
|||||||
redisserver:
|
|
||||||
address: localhost:6379
|
|
||||||
password:
|
|
||||||
db:
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user