| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- package proto
- import (
- "context"
- "bet24.com/log"
- "bet24.com/servers/micros/common"
- "github.com/smallnest/rpcx/client"
- )
- const ServiceName = "platformconfig"
- const NOTIFY_MESSAGE = "RefreshRedisConfig"
- var consulAddr = common.Default_Consul_Addr
- func getClient() client.XClient {
- return common.GetClientPool().GetClient(ServiceName, consulAddr)
- }
- type Request struct {
- Name string
- Value string
- }
- type Response struct {
- Data string
- List []string
- }
- func SetConsulAddr(addr string) {
- consulAddr = addr
- }
- func SayHello(name string) string {
- xclient := getClient()
- args := &Request{
- Name: name,
- }
- reply := &Response{}
- err := xclient.Call(context.Background(), "SayHello", args, reply)
- if err != nil {
- log.Debug("platformconfig failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return ""
- }
- log.Debug("SayHello return %s", reply.Data)
- return reply.Data
- }
- func GetConfig(name string) string {
- xclient := getClient()
- args := &Request{
- Name: name,
- }
- reply := &Response{}
- err := xclient.Call(context.Background(), "GetConfig", args, reply)
- if err != nil {
- log.Debug("platformconfig failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return ""
- }
- return reply.Data
- }
- func SetConfig(name string, value string) {
- xclient := getClient()
- args := &Request{
- Name: name,
- Value: value,
- }
- err := xclient.Call(context.Background(), "SetConfig", args, nil)
- if err != nil {
- log.Debug("platformconfig failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return
- }
- }
- func GetConfigList() []string {
- xclient := getClient()
- args := &Request{}
- reply := &Response{}
- err := xclient.Call(context.Background(), "GetConfigList", args, reply)
- if err != nil {
- log.Debug("platformconfig failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return []string{}
- }
- return reply.List
- }
- func GetChangeLog(key string) string {
- xclient := getClient()
- args := &Request{Name: key}
- reply := &Response{}
- err := xclient.Call(context.Background(), "GetChangeLog", args, reply)
- if err != nil {
- log.Debug("platformconfig failed to call: %v", err)
- common.GetClientPool().RemoveClient(ServiceName)
- return ""
- }
- return reply.Data
- }
|