Skip to content

Commit

Permalink
protoeasy --grpc --go --go-import-path github.com/nytimes/gizmo/examp…
Browse files Browse the repository at this point in the history
…les examples, update code for new protobuf gen files
  • Loading branch information
bufdev committed Dec 19, 2015
1 parent 526bf2e commit cb2c4ae
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 126 deletions.
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.

2 changes: 1 addition & 1 deletion examples/nyt/mostpopular.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
syntax = "proto3";

import "google/type/date.proto"
import "google/type/date.proto";

package nyt;

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: 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

0 comments on commit cb2c4ae

Please sign in to comment.