1- package limitserver
1+ package limit_server
22
33import (
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+ }
0 commit comments