Commit dd1bff0b authored by vicotor's avatar vicotor

update config

parent 50317747
endpoint="127.0.0.1:10001" host="127.0.0.1"
port=10001
metrics_port = 28010 metrics_port = 28010
private_key = "E671C143A110C239B563F702E9F4017CA6B2B2912F675EED9AA4FED684EB30CC" private_key = "E671C143A110C239B563F702E9F4017CA6B2B2912F675EED9AA4FED684EB30CC"
enable_pay = false enable_pay = false
......
package config package config
import ( import (
"fmt"
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"io/ioutil" "io/ioutil"
...@@ -34,8 +35,10 @@ type TickerConfig struct { ...@@ -34,8 +35,10 @@ type TickerConfig struct {
} }
type Config struct { type Config struct {
PrivateKey string `json:"private_key" toml:"private_key"` PrivateKey string `json:"private_key" toml:"private_key"`
Endpoint string `json:"endpoint" toml:"endpoint"` Host string `json:"host" toml:"host"`
Port int `json:"port" toml:"port"`
//Endpoint string `json:"endpoint" toml:"endpoint"`
MetricPort int `json:"metrics_port" toml:"metrics_port"` MetricPort int `json:"metrics_port" toml:"metrics_port"`
EnablePay bool `json:"enable_pay" toml:"enable_pay"` EnablePay bool `json:"enable_pay" toml:"enable_pay"`
Redis RedisConfig `json:"redis" toml:"redis"` Redis RedisConfig `json:"redis" toml:"redis"`
...@@ -64,3 +67,10 @@ func ParseConfig(path string) (*Config, error) { ...@@ -64,3 +67,10 @@ func ParseConfig(path string) (*Config, error) {
func GetConfig() *Config { func GetConfig() *Config {
return _cfg return _cfg
} }
func (conf *Config) PublicEndpoint() string {
return fmt.Sprintf("%s:%d", conf.Host, conf.Port)
}
func (conf *Config) ApiEndpoint() string {
return fmt.Sprintf("0.0.0.0:%d", conf.Port)
}
...@@ -88,10 +88,12 @@ func (s *RegistryService) registry(rdb *redis.Client) error { ...@@ -88,10 +88,12 @@ func (s *RegistryService) registry(rdb *redis.Client) error {
addr := utils.PrivatekeyToHex(priv) addr := utils.PrivatekeyToHex(priv)
pubHex := utils.PubkeyToHex(&priv.PublicKey) pubHex := utils.PubkeyToHex(&priv.PublicKey)
endpoint := fmt.Sprintf("%s:%d", s.conf.Host, s.conf.Port)
err = rdb.HSet(context.Background(), config.NODE_MANAGER_SET+addr, RegistryInfo{ err = rdb.HSet(context.Background(), config.NODE_MANAGER_SET+addr, RegistryInfo{
Pubkey: pubHex, Pubkey: pubHex,
Timestamp: time.Now().Unix(), Timestamp: time.Now().Unix(),
Endpoint: s.conf.Endpoint, Endpoint: endpoint,
Addr: addr, Addr: addr,
}).Err() }).Err()
return err return err
......
...@@ -88,7 +88,7 @@ func (n *Node) Start() error { ...@@ -88,7 +88,7 @@ func (n *Node) Start() error {
} }
func (n *Node) apiStart() error { func (n *Node) apiStart() error {
lis, err := net.Listen("tcp", config.GetConfig().Endpoint) lis, err := net.Listen("tcp", config.GetConfig().ApiEndpoint())
if err != nil { if err != nil {
log.WithError(err).Error("failed to listen endpoint") log.WithError(err).Error("failed to listen endpoint")
return err return err
......
...@@ -22,16 +22,16 @@ func (wm *WorkerManager) AddWorker(worker *Worker) error { ...@@ -22,16 +22,16 @@ func (wm *WorkerManager) AddWorker(worker *Worker) error {
} }
} }
// add worker to redis queue // add worker to redis queue
if err := wm.rdb.SAdd(context.Background(), config.WORKER_STATUS_PREFIX+worker.addr, config.GetConfig().Endpoint).Err(); err != nil { if err := wm.rdb.SAdd(context.Background(), config.WORKER_STATUS_PREFIX+worker.addr, config.GetConfig().PublicEndpoint()).Err(); err != nil {
return err return err
} }
return nil return nil
} }
func (wm *WorkerManager) ActiveWorker(worker *Worker) { func (wm *WorkerManager) ActiveWorker(worker *Worker) {
wm.rdb.SAdd(context.Background(), config.WORKER_STATUS_PREFIX+worker.addr, config.GetConfig().Endpoint) wm.rdb.SAdd(context.Background(), config.WORKER_STATUS_PREFIX+worker.addr, config.GetConfig().PublicEndpoint())
} }
func (wm *WorkerManager) InActiveWorker(worker *Worker) { func (wm *WorkerManager) InActiveWorker(worker *Worker) {
wm.rdb.SRem(context.Background(), config.WORKER_STATUS_PREFIX+worker.addr, config.GetConfig().Endpoint) wm.rdb.SRem(context.Background(), config.WORKER_STATUS_PREFIX+worker.addr, config.GetConfig().PublicEndpoint())
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment