func (rc *RobotController) streamRegisterNotification() error {
ctx := context.Background()
stream, err := (*rc.client).RegisterNotification(ctx, &empty.Empty{})
if err != nil {
log().Errorf("get notification stream err: %v", err)
return err
}
defer func() {
stream.CloseSend()
}()
for {
data, err := stream.Recv()
if err == io.EOF {
log().Error("notification run io.EOF")
break
}
if err != nil {
log().Errorf("notification recv err:%v, data: %v", err.Error(), data)
return err
}
// process the notification
}
return nil
}
The protobuf definition defines here
message Notice {
enum NoticeType {
NOTICE_STATE = 0;
NOTICE_ERROR = 1;
NOTICE_BUTTON = 2;
}
enum NoticeId {
NOTICE_ID_1 = 0;
NOTICE_ID_2 = 1;
}
NoticeType type = 1;
NoticeId id = 2;
int32 value = 3;
int32 code = 4;
repeated double lol = 5;
}
message Notification {
repeated Notice items = 1;
}
service RobotController {