Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tmc/grpc-websocket-proxy
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: tmc/grpc-websocket-proxy
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: timestamp_stdtime_example
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 3 commits
  • 6 files changed
  • 1 contributor

Commits on Sep 30, 2016

  1. show example timestamp use

    tmc committed Sep 30, 2016
    Copy the full SHA
    5685d1d View commit details

Commits on Oct 17, 2016

  1. wip: testing

    tmc committed Oct 17, 2016
    Copy the full SHA
    8a91140 View commit details
  2. add gogoproto.stdtime example

    tmc committed Oct 17, 2016
    Copy the full SHA
    7fb0c0a View commit details
3 changes: 2 additions & 1 deletion examples/cmd/wsechoserver/echoserver/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
all:
protoc -I/usr/local/include -I. \
-I${GOPATH}/src \
-I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--go_out=Mgoogle/api/annotations.proto=github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/google/api,plugins=grpc:. \
--gogo_out=Mgoogle/api/annotations.proto=github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/google/api,plugins=grpc:. \
--grpc-gateway_out=logtostderr=true:. \
echoserver.proto
1,430 changes: 1,378 additions & 52 deletions examples/cmd/wsechoserver/echoserver/echoserver.pb.go

Large diffs are not rendered by default.

122 changes: 118 additions & 4 deletions examples/cmd/wsechoserver/echoserver/echoserver.pb.gw.go
36 changes: 36 additions & 0 deletions examples/cmd/wsechoserver/echoserver/echoserver.proto
Original file line number Diff line number Diff line change
@@ -2,13 +2,35 @@ syntax = "proto3";
package echoserver;

import "google/api/annotations.proto";
import "google/protobuf/timestamp.proto";

import "github.com/gogo/protobuf/gogoproto/gogo.proto";

// Disables some golang/protobuf behaviour
option (gogoproto.goproto_stringer_all) = false;
option (gogoproto.goproto_enum_stringer_all) = false;
option (gogoproto.gostring_all) = false;

// Enable gogo/protobuf features
option (gogoproto.populate_all) = true;
option (gogoproto.sizer_all) = true;
option (gogoproto.stringer_all) = true;
option (gogoproto.equal_all) = true;
option (gogoproto.verbose_equal_all) = true;
option (gogoproto.marshaler_all) = true;
option (gogoproto.unmarshaler_all) = true;
option (gogoproto.enum_stringer_all) = true;

message EchoRequest {
string message = 1;
}

message EchoResponse {
string message = 1;
google.protobuf.Timestamp timestamp = 2 [
(gogoproto.stdtime) = true,
(gogoproto.nullable) = false
];
}

message Heartbeat {
@@ -32,3 +54,17 @@ service EchoService {
option (google.api.http) = {post: "/heartbeats"};
}
}


service Messaging {
rpc UpdateMessage(Message) returns (Message) {
option (google.api.http) = {
put: "/v1/messages/{message_id}"
body: "*"
};
}
}
message Message {
string message_id = 1;
string text = 2;
}
14 changes: 10 additions & 4 deletions examples/cmd/wsechoserver/main.go
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ import (
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/tmc/grpc-websocket-proxy/examples/cmd/wsechoserver/echoserver"
"github.com/tmc/grpc-websocket-proxy/wsproxy"
"github.com/tmc/grpcutils"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
@@ -33,15 +34,18 @@ func run() error {
return err
}

mux := runtime.NewServeMux()
mux := runtime.NewServeMux(runtime.WithMarshalerOption("*", &grpcutils.JSONPb{OrigName: true}))
opts := []grpc.DialOption{grpc.WithInsecure()}
err := echoserver.RegisterEchoServiceHandlerFromEndpoint(ctx, mux, *grpcAddr, opts)
if err != nil {
if err := echoserver.RegisterEchoServiceHandlerFromEndpoint(ctx, mux, *grpcAddr, opts); err != nil {
return err
}
if err := echoserver.RegisterMessagingHandlerFromEndpoint(ctx, mux, *grpcAddr, opts); err != nil {
return err
}
go http.ListenAndServe(*debugAddr, nil)
fmt.Println("listening")
http.ListenAndServe(*httpAddr, wsproxy.WebsocketProxy(mux))
//log.Fatalnln(http.ListenAndServe(*httpAddr, mux))
log.Fatalln(http.ListenAndServe(*httpAddr, wsproxy.WebsocketProxy(mux)))
return nil
}

@@ -52,6 +56,8 @@ func listenGRPC(listenAddr string) error {
}
grpcServer := grpc.NewServer()
echoserver.RegisterEchoServiceServer(grpcServer, &Server{})
echoserver.RegisterMessagingServer(grpcServer, &Server{})

go func() {
if err := grpcServer.Serve(lis); err != nil {
log.Println("serveGRPC err:", err)
18 changes: 17 additions & 1 deletion examples/cmd/wsechoserver/server.go
Original file line number Diff line number Diff line change
@@ -5,13 +5,21 @@ import (
"fmt"
"time"

"golang.org/x/net/context"

log "github.com/Sirupsen/logrus"
"github.com/davecgh/go-spew/spew"
"github.com/golang/protobuf/jsonpb"
"github.com/tmc/grpc-websocket-proxy/examples/cmd/wsechoserver/echoserver"
)

type Server struct{}

func (s *Server) UpdateMessage(ctx context.Context, m *echoserver.Message) (*echoserver.Message, error) {
spew.Dump(m)
return &echoserver.Message{}, nil
}

func (s *Server) Stream(_ *echoserver.Empty, stream echoserver.EchoService_StreamServer) error {
start := time.Now()
for i := 0; i < 5; i++ {
@@ -31,8 +39,16 @@ func (s *Server) Echo(srv echoserver.EchoService_EchoServer) error {
if err != nil {
return err
}
now := time.Now()
if err := srv.Send(&echoserver.EchoResponse{
Message: req.Message + "!",
Message: req.Message + "!",
Timestamp: now,
/*
Timestamp: &timestamp.Timestamp{
Seconds: now.Unix(),
Nanos: int32(now.Nanosecond()),
},
*/
}); err != nil {
return err
}