addr, err := room.GetRoomNodeAddress(roomID)if err !=nil {// Handle errorreturn}req :=make(map[string]interface{})req["roomID"] = roomID// passcode comes from the clientreq["passcode"] = passcode// mesh.SendRequest is a inter-pod communication functionmesh.SendRequest(cmdID, addr, req, func(err error, res map[string]interface{}) {if err !=nil {// Handle errorreturn }// The room has been unlocked successfully})
mesh.Command(cmdID, unlockRoom)funcunlockRoom(req map[string]interface{}) (error, map[string]interface{}) { roomID := mesh.GetString(req, "roomID") passcode := mesh.GetString(req, "passcode")var err error _ := room.UpdateProperties(roomID, func(props map[string]interface{}) bool {if _, ok := props["unlocked"].(bool); !ok {// the room is already unlocked err := errors.New("Room already unlocked")returnfalse }if _, ok := props["passcode"].(string); !ok {// missing pass code... err := errors.New("Room is missing passcode...")returnfalse }if passcode != props["passcode"].(string) {// pass code the client has does not match err := errors.New("Pass code does not match")returnfalse }// pass code the client has matches props["unlocked"] =truereturntrue }) res :=make(map[string]interface{})return res, err}