I have an api created via golang which return the result of
{
id : drone4
item_parameter : {
altitude : 20,
longitude : 10.20
latitude : 24.5
}
as a json result, but in the code it uses go routines which call the go func() to process the result from grpc-server golang
like this
go func() {
fmt.Print("start getPosition loop")
for {
msg, err := stream.Recv() // msg UAVPosition
if err == io.EOF {
// read done.
fmt.Print("start getPosition loop closed")
close(position)
return
}
if err != nil {
log.Fatalf("Failed to receive getPosition : %v", err)
close(position)
return
}
log.Printf("Position point[%s](%f, %f, %f)", uavID.Aircraft, msg.Latitude, msg.Longitude, msg.Altitude)
itemParameter := models.ItemParameter{
Latitude: msg.Latitude,
Longitude: msg.Longitude,
Altitude: msg.Altitude,
}
position <- models.DronePosition{
Name: uavID.Aircraft,
ItemParameter: itemParameter,
}
}
}()
I need to get the positon value which is i used this channel
position := make(chan models.DronePosition)
if any chance how can I get this result to stream to the ui using go? any suggestion how to work this streaming way in ui?
If I understood you correctly -> this is server grpc endpoint and your problem is how to send models.DronePosition
back to the client. If so, then you have bidirectional streaming and you can solve this problem as:
dronePosition := models.DronePosition{
Name: uavID.Aircraft,
ItemParameter: itemParameter,
}
position <- dronePosition
err = stream.Send(&dronePosition)
And on the client there should be the corresponding update to support bidirectional data streaming