/
registryServer.go
71 lines (59 loc) · 1.3 KB
/
registryServer.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
"github.com/go-redis/redis"
"jsonrpc"
"jsonrpc/common"
registryService "jsonrpc/registry"
)
var client *redis.Client
// Registry definition
type Registry struct {
}
// RedisOptions definition
type RedisOptions struct {
Tag string
Host string
Port string
Password string
DB int
PoolSize int
}
// RedisDbOptions definition
type RedisDbOptions struct {
Master RedisOptions
Slave []RedisOptions
}
// GetIP publishes the receiver's methods GetIP in the DefaultServer.
func (registry *Registry) GetIP(_, reply *string) error {
*reply = registryService.GetIP()
return nil
}
func init() {
kvs := RedisDbOptions{}
JSONParse := common.NewJSONStruct()
JSONParse.Load("config/redis.json", &kvs)
host := kvs.Master.Host
port := kvs.Master.Port
password := kvs.Master.Password
poolSize := kvs.Master.PoolSize
dbName := kvs.Master.DB
client = redis.NewClient(&redis.Options{
Addr: host + ":" + port,
Password: password,
DB: dbName,
PoolSize: poolSize,
})
_, err := client.Ping().Result()
//fmt.Println(pong, err)
if err != nil {
panic(err)
}
registryService.Inject(client)
registryService.HealthCheck()
}
func main() {
jsonrpc.Register(new(Registry))
fmt.Println("registry server running.")
jsonrpc.ListenAndServe("tcp", ":1231")
}