addrlist, err := room.GetRoomNodeAddressList(roomID)if err !=nil {// Handle errorreturn } req :=make(map[string]interface{}) req["roomID"] = roomID addr := addrlist[0] // the rest in the array are the backups mesh.SendRequest(cmdID, addr, req, func(err error, res map[string]interface{}) {if err !=nil {// Handle errorreturn }// Remote room property updated successfully})
リモート・サーバ・ノードでのロジックの更新
// This sets up handleRemoteRoomPropUpdate function to be invoked when mesh.SendRequest sends// the command message as shown abovemesh.Command(cmdID, handleRemoteRoomPropUpdate)funchandleRemoteRoomPropUpdate(req map[string]interface{}) (error, map[string]interface{}) { roomID := mesh.GetString(req, "roomID")var err error _ := room.UpdateProperties(roomID, func(props map[string]interface{}) bool {if _, ok := props["booked"]; !ok { props["booked"] =true// Booked the room successfullyreturntrue }// The room has already been booked... err = errors.New("Room has already been booked")returnfalse }) res :=make(map[string]interface{})return res, err}