#Protos

2 messages · Page 1 of 1 (latest)

rugged minnow
#

Hi, I started messing around with grpc. Lets say I have protos defined in my protos package. Im making a server that provides sensor data from multiple sensor providers, so my project structure is

providers/
  providerA/
    sensor.go
  providerB/
    sensor.go
  providerC/
    sensor.go
protos/
  sensors.proto
main.go

My protos define GetSensorRequest and GetSensorResponse

message GetSensorRequest{}

message GetSensorResponse {
    float Temperature = 1;
}

In main.go I have an interface

type SensorDataGetter struct {
  GetSensorData() protos.GetSensorResponse
}

// and a list of getters that implement SensorDataGetter (provoders package)
var getters = []SensorDataGetter {
  &providerA{},
  &providerB{},
  &providerC{},
}

Now, should my interface have a return that is directly the proto response that I need (like now in this example), or should I have an intermediate type like:

type SensorData struct {
  Temperature float64
}

So my providers dont return the proto response, they return SensorData which is then used to create a GetSensorResponse from the server. Is there a good or bad approach here, or its a preference, what would be the mainstream way?

twin scarab
#

is this the sensordata I am thinking about? kekwhy