Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protobuf file cleanup #10

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/nyt/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (c *ClientImpl) GetMostPopular(resourceType string, section string, timePer
}

err = json.Unmarshal(rawRes, &res)
return res.Results, err
return res.Result, err
}

func (c *ClientImpl) SemanticConceptSearch(conceptType, concept string) ([]*SemanticConceptArticle, error) {
Expand All @@ -58,11 +58,11 @@ func (c *ClientImpl) SemanticConceptSearch(conceptType, concept string) ([]*Sema
}

err = json.Unmarshal(rawRes, &res)
if len(res.Results) == 0 {
if len(res.Result) == 0 {
return nil, errors.New("no results")
}

return res.Results[0].ArticleList.Results, nil
return res.Result[0].ArticleList.Result, nil
}

func (c *ClientImpl) do(uri string) (body []byte, err error) {
Expand Down
100 changes: 55 additions & 45 deletions examples/nyt/mostpopular.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions examples/nyt/mostpopular.proto
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
syntax = "proto3";

import "google/type/date.proto";

package nyt;

message MostPopularResponse {
string status = 1;
string copyright = 2;
uint32 num_results = 3;
repeated MostPopularResult results = 4;
repeated MostPopularResult result = 4;
}

message MostPopularResult {
Expand All @@ -20,7 +22,7 @@ message MostPopularResult {
string type = 8;
string title = 9;
string abstract = 10;
string published_date = 11;
google.type.Date published_date = 11;
string source = 12;
uint32 views = 13;
repeated Media media = 14;
Expand Down
48 changes: 24 additions & 24 deletions examples/nyt/semanticconcept.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/nyt/semanticconcept.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ message SemanticConceptResponse {
string status = 1;
string copyright = 2;
uint32 num_results = 3;
repeated SemanticConceptResult results = 4;
repeated SemanticConceptResult result = 4;
}

message SemanticConceptResult {
SemanticConceptArticleList article_list = 1;
}

message SemanticConceptArticleList {
repeated SemanticConceptArticle results = 1;
repeated SemanticConceptArticle result = 1;
uint32 total = 2;
}

Expand Down
4 changes: 3 additions & 1 deletion examples/servers/rpc/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"log"
"os"

"go.pedge.io/google-protobuf"

"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/grpclog"
Expand Down Expand Up @@ -53,7 +55,7 @@ func main() {
}

if *catsFlag {
cats, err := nytClient.GetCats(context.Background(), &service.CatsRequest{})
cats, err := nytClient.GetCats(context.Background(), google_protobuf.EmptyInstance)
if err != nil {
log.Fatal("get cats list: ", err)
}
Expand Down
8 changes: 5 additions & 3 deletions examples/servers/rpc/service/cats.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package service
import (
"net/http"

"go.pedge.io/google-protobuf"

"github.com/nytimes/gizmo/examples/nyt"
"github.com/nytimes/gizmo/server"
"golang.org/x/net/context"
)

func (s *RPCService) GetCats(ctx context.Context, r *CatsRequest) (*CatsResponse, error) {
func (s *RPCService) GetCats(ctx context.Context, r *google_protobuf.Empty) (*CatsResponse, error) {
var (
err error
res []*nyt.SemanticConceptArticle
Expand All @@ -24,9 +26,9 @@ func (s *RPCService) GetCats(ctx context.Context, r *CatsRequest) (*CatsResponse
}

func (s *RPCService) GetCatsJSON(r *http.Request) (int, interface{}, error) {
res, err := s.GetCats(context.Background(), &CatsRequest{})
res, err := s.GetCats(context.Background(), google_protobuf.EmptyInstance)
if err != nil {
return http.StatusInternalServerError, nil, err
}
return http.StatusOK, res.Results, nil
return http.StatusOK, res.Result, nil
}
2 changes: 1 addition & 1 deletion examples/servers/rpc/service/mostpopular.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ func (s *RPCService) GetMostPopularJSON(r *http.Request) (int, interface{}, erro
if err != nil {
return http.StatusInternalServerError, nil, err
}
return http.StatusOK, res.Results, nil
return http.StatusOK, res.Result, nil
}
Loading