dashboard/services/unis/common.go

47 lines
882 B
Go

package unis
import (
"dashboard/models"
"dashboard/pkg/rpcsup"
"fmt"
"net/rpc"
)
type rpcClients map[string]*rpc.Client
var rpcMapClients rpcClients
func StationConfig(config *models.StationConfigParams) error {
CreateRpcClients(&rpcMapClients, &config.StationConfig.Screens)
fmt.Println(GetConfig(models.UnisRpcRequest{Id: "zhangshuo"}))
return nil
}
func CreateRpcClients(rawClients *rpcClients, screens *[]models.Screens) {
if *rawClients == nil {
*rawClients = make(map[string]*rpc.Client)
}
for _, cli := range *rawClients {
if cli != nil {
cli.Close()
}
}
for _, sc := range *screens {
id := sc.NodeID
address := fmt.Sprintf("%s:%d", sc.NodeIP, 5501)
cli, err := rpcsup.JsonClient(log, address)
if err != nil {
log.Sugar().Errorf("%s create rpc client error: %s", id, address)
continue
}
(*rawClients)[id] = cli
}
return
}