metaverse / truss

Truss helps you build go-kit microservices without having to worry about writing or maintaining boilerplate code.
Other
734 stars 143 forks source link

Generated CLIs do not compile when using `oneof` #281

Closed zaquestion closed 4 years ago

zaquestion commented 4 years ago

Kinda weird issue using oneof, not sure how we're going to address. Service works correct and marshals as expected, but generated CLI is borked

search-service/svc/client/cli/handlers/handlers.go

// GetTasks implements Service.
func GetTasks(SearchGetTasks isSearchRequest_Search) (*pb.SearchRequest, error) {
    request := pb.SearchRequest{
        Search:       SearchGetTasks,
    }
    return &request, nil
}

// GetAgents implements Service.
func GetAgents(SearchGetAgents isSearchRequest_Search) (*pb.SearchRequest, error) {
    request := pb.SearchRequest{
        Search:       SearchGetAgents,
    }
    return &request, nil
}

Note above that isSearchRequest_Search doesn't have the pb. package prefix, and even if it did isSearchRequest is unexported which makes it challenging to reference here

service.proto

message SearchRequest {
  oneof search {
    string query = 1;
    string ids   = 2;
  }
}

service.pb.go

type SearchRequest struct {
    // Types that are valid to be assigned to Search:
    //  *SearchRequest_Query
    //  *SearchRequest_Ids
    Search isSearchRequest_Search `protobuf_oneof:"search"`
}

type isSearchRequest_Search interface {
    isSearchRequest_Search()
    MarshalTo([]byte) (int, error)
    Size() int
}

type SearchRequest_Query struct {
    Query string `protobuf:"bytes,5,opt,name=query,proto3,oneof"`
}
type SearchRequest_Ids struct {
    Ids string `protobuf:"bytes,6,opt,name=ids,proto3,oneof"`
}
zaquestion commented 4 years ago

There is a suggested change: https://github.com/golang/protobuf/pull/588 that would technically allow complication, though I'm not sure that is enough to actually make these CLIs function with oneof.

zaquestion commented 4 years ago

It seems like our implementation of the CLI clients will need to be aware of oneof and generate flags for each of the underlying fields and enforce the "one of" behavior on itself. The underlying flags would then need to be place into types that can meet the underlying interface.

zaquestion commented 4 years ago

cli clients were removed.