Skip to content

Commit 5722b25

Browse files
committed
Successfully streaming Data
1 parent d553fd3 commit 5722b25

5 files changed

Lines changed: 483 additions & 32 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ To run this project, you will need to add the following environment variables to
3737

3838
- [Keyur Shah](https://www.github.com/keyurboss)
3939

40+
protoc proto/limit-server.proto --go_out=. --go-grpc_out=.

proto/limit-server.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ syntax = "proto3";
22

33
package proto;
44

5-
option go_package = "github.com/rpsoftech/bullion-server/proto/limit-server";
5+
option go_package = "src/limit-server";
66

77
message UplinkPlaceLimitRequest {
88
string reqId = 1;

src/limit-server/index.go

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
1-
package limitserver
1+
package limit_server
22

33
import (
44
"context"
5+
"io"
56
"net"
67

7-
proto "github.com/rpsoftech/bullion-server/proto"
88
"google.golang.org/grpc"
99
"google.golang.org/grpc/reflection"
1010
)
1111

12-
type LimitServerServer struct{}
12+
type LimitServerService struct{}
1313

14-
func (LimitServerServer) PlaceLimit(context.Context, *proto.UplinkPlaceLimitRequest) (*proto.UplinkPlaceLimitResponse, error) {
15-
panic("unimplemented")
16-
}
17-
func (LimitServerServer) testEmbeddedByValue() {}
18-
func (LimitServerServer) PlaceLimitStream(grpc.BidiStreamingServer[proto.UplinkPlaceLimitRequest, proto.UplinkPlaceLimitResponse]) error {
19-
panic("unimplemented")
20-
}
21-
22-
func (LimitServerServer) mustEmbedUnimplementedLimitServerServer() {
14+
func (LimitServerService) mustEmbedUnimplementedLimitServerServer() {
2315
panic("unimplemented")
2416
}
2517

@@ -31,29 +23,45 @@ func Start() {
3123
srv := grpc.NewServer(
3224
// grpc.UnaryInterceptor()
3325
)
34-
// proto.re
35-
proto.RegisterLimitServerServer(srv, &LimitServerServer{})
26+
// re
27+
RegisterLimitServerServer(srv, &LimitServerService{})
3628
reflection.Register(srv)
3729

3830
if e := srv.Serve(lis); e != nil {
3931
panic(err)
4032
}
4133
}
4234

43-
// func (s *LimitServer) mustEmbedUnimplementedLimitServerServer() {}
44-
// func (s *LimitServer) PlaceLimitStream(a grpc.BidiStreamingServer[*proto.UplinkPlaceLimitRequest, *proto.UplinkPlaceLimitResponse]) error {
45-
// return nil
46-
// }
47-
48-
// // func (s *LimitServer) PlaceLimit(context.Context, *UplinkPlaceLimitRequest) (*UplinkPlaceLimitResponse, error) {
49-
// // }
50-
51-
// func (s *LimitServer) PlaceLimit(_ context.Context, request *proto.UplinkPlaceLimitRequest) (*proto.UplinkPlaceLimitResponse, error) {
52-
// bullionId, weight, price := request.GetBullionId(), request.GetWeight(), request.GetPrice()
53-
// println(bullionId, weight, price)
54-
// return &proto.UplinkPlaceLimitResponse{
55-
// ReqId: request.GetReqId(),
56-
// Success: true,
57-
// Message: "",
58-
// }, nil
59-
// }
35+
func (s *LimitServerService) PlaceLimitStream(stream grpc.BidiStreamingServer[UplinkPlaceLimitRequest, UplinkPlaceLimitResponse]) error {
36+
// panic("unimplemented")
37+
for {
38+
request, err := stream.Recv()
39+
bullionId, weight, price := request.GetBullionId(), request.GetWeight(), request.GetPrice()
40+
if err == io.EOF {
41+
return nil
42+
}
43+
if err != nil {
44+
return err
45+
}
46+
println(bullionId, weight, price)
47+
stream.Send(&UplinkPlaceLimitResponse{
48+
ReqId: request.GetReqId(),
49+
Success: true,
50+
Message: "",
51+
})
52+
// for _, note := range s.routeNotes[key] {
53+
// if err := stream.Send(note); err != nil {
54+
// return err
55+
// }
56+
// }
57+
}
58+
}
59+
func (s *LimitServerService) PlaceLimit(_ context.Context, request *UplinkPlaceLimitRequest) (*UplinkPlaceLimitResponse, error) {
60+
bullionId, weight, price := request.GetBullionId(), request.GetWeight(), request.GetPrice()
61+
println(bullionId, weight, price)
62+
return &UplinkPlaceLimitResponse{
63+
ReqId: request.GetReqId(),
64+
Success: true,
65+
Message: "",
66+
}, nil
67+
}

src/limit-server/limit-server.pb.go

Lines changed: 288 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)