这是我写的重连,请指教
<pre>
<code class="language-go">
package main
var bBClient *rpc.Client
var conn net.Conn
func GetInstance() *rpc.Client {
if conn != nil {
err := conn.SetReadDeadline(time.Now().Add(time.Second * 1))
if err != nil {
log.Fatal("setread-----", err)
bBClient = nil
}
} else {
logs.Debug("conn2", conn)
}
if bBClient == nil {
return instance()
}
return bBClient
}
func instance() *rpc.Client {
conn, err := net.Dial("tcp", beego.AppConfig.String("BBRpc"))
if err != nil {
log.Fatal("dialing:", err)
}
return jsonrpc.NewClient(conn)
}
func init() {
instance()
}
</code></pre>