go-zero rpc配置

2022-04-25 17:47 更新

rpc配置

rpc配置控制著一個(gè)rpc服務(wù)的各種功能,包含但不限于監(jiān)聽(tīng)地址,etcd配置,超時(shí),熔斷配置等,下面我們以一個(gè)常見(jiàn)的rpc服務(wù)配置來(lái)進(jìn)行說(shuō)明。

配置說(shuō)明

Config struct {
    zrpc.RpcServerConf
    CacheRedis         cache.CacheConf // redis緩存配置,詳情見(jiàn)api配置說(shuō)明,這里不贅述
    Mysql struct { // mysql數(shù)據(jù)庫(kù)訪問(wèn)配置,詳情見(jiàn)api配置說(shuō)明,這里不贅述
        DataSource string
    }
}

zrpc.RpcServerConf

RpcServerConf struct {
    service.ServiceConf // 服務(wù)配置,詳情見(jiàn)api配置說(shuō)明,這里不贅述
    ListenOn      string // rpc監(jiān)聽(tīng)地址和端口,如:127.0.0.1:8888
    Etcd          discov.EtcdConf    `json:",optional"` // etcd相關(guān)配置
    Auth          bool               `json:",optional"` // 是否開(kāi)啟Auth,如果是則Redis為必填
    Redis         redis.RedisKeyConf `json:",optional"` // Auth驗(yàn)證
    StrictControl bool               `json:",optional"` // 是否Strict模式,如果是則遇到錯(cuò)誤是Auth失敗,否則可以認(rèn)為成功
    // pending forever is not allowed
    // never set it to 0, if zero, the underlying will set to 2s automatically
    Timeout      int64 `json:",default=2000"` // 超時(shí)控制,單位:毫秒
    CpuThreshold int64 `json:",default=900,range=[0:1000]"` cpu降載閾值,默認(rèn)900,可允許設(shè)置范圍0到1000
}

discov.EtcdConf

type EtcdConf struct {
    Hosts []string // etcd host數(shù)組
    Key   string // rpc注冊(cè)key
}

redis.RedisKeyConf

RedisConf struct {
    Host string // redis 主機(jī)
    Type string `json:",default=node,options=node|cluster"` // redis類型
    Pass string `json:",optional"` // redis密碼
}

RedisKeyConf struct {
    RedisConf
    Key string `json:",optional"` // 驗(yàn)證key
}


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)