10 examples of 'golang streaming' in Go

Every line of 'golang streaming' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
1018func (builder *ListKeysCommandBuilder) WithStreaming(streaming bool) *ListKeysCommandBuilder {
1019 builder.streaming = streaming
1020 return builder
1021}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

125func (c *benchmarkServiceClient) StreamingFromServer(ctx context.Context, in *SimpleRequest, opts ...grpc.CallOption) (BenchmarkService_StreamingFromServerClient, error) {
126 stream, err := c.cc.NewStream(ctx, &BenchmarkService_ServiceDesc.Streams[2], "/grpc.testing.BenchmarkService/StreamingFromServer", opts...)
127 if err != nil {
128 return nil, err
129 }
130 x := &benchmarkServiceStreamingFromServerClient{stream}
131 if err := x.ClientStream.SendMsg(in); err != nil {
132 return nil, err
133 }
134 if err := x.ClientStream.CloseSend(); err != nil {
135 return nil, err
136 }
137 return x, nil
138}
82func (c *Client) streaming(ctx context.Context, p string, params url.Values) (chan Event, error) {
83 u, err := url.Parse(c.config.Server)
84 if err != nil {
85 return nil, err
86 }
87 u.Path = path.Join(u.Path, "/api/v1/streaming", p)
88 u.RawQuery = params.Encode()
89
90 req, err := http.NewRequest(http.MethodGet, u.String(), nil)
91 if err != nil {
92 return nil, err
93 }
94 req = req.WithContext(ctx)
95 req.Header.Set("Authorization", "Bearer "+c.config.AccessToken)
96
97 q := make(chan Event)
98 go func() {
99 defer close(q)
100 for {
101 select {
102 case <-ctx.Done():
103 return
104 default:
105 }
106
107 c.doStreaming(req, q)
108 }
109 }()
110 return q, nil
111}
589func (*UnimplementedTestServiceServer) EchoStreamTest(req *EchoStreamTest_Request, srv TestService_EchoStreamTestServer) error {
590 return status.Errorf(codes.Unimplemented, "method EchoStreamTest not implemented")
591}
69func (s *testServer) StreamingCall(stream testpb.BenchmarkService_StreamingCallServer) error {
70 in := new(testpb.SimpleRequest)
71 for {
72 // use ServerStream directly to reuse the same testpb.SimpleRequest object
73 err := stream.(grpc.ServerStream).RecvMsg(in)
74 if err == io.EOF {
75 // read done.
76 return nil
77 }
78 if err != nil {
79 return err
80 }
81
82 response := &testpb.SimpleResponse{
83 Payload: NewPayload(in.ResponseType, int(in.ResponseSize)),
84 }
85 if err := stream.Send(response); err != nil {
86 return err
87 }
88 }
89}
202func (m *MockCloudSpanner) StreamingRead(r *sppb.ReadRequest, s sppb.Spanner_StreamingReadServer) error {
203 m.t.Fatalf("StreamingRead is unimplemented")
204 return errors.New("Unimplemented")
205}
196func (c *exampleClient) Stream(ctx context.Context, in *StreamingRequest, opts ...grpc.CallOption) (Example_StreamClient, error) {
197 stream, err := grpc.NewClientStream(ctx, &_Example_serviceDesc.Streams[0], c.cc, "/go.micro.srv.example.Example/Stream", opts...)
198 if err != nil {
199 return nil, err
200 }
201 x := &exampleStreamClient{stream}
202 if err := x.ClientStream.SendMsg(in); err != nil {
203 return nil, err
204 }
205 if err := x.ClientStream.CloseSend(); err != nil {
206 return nil, err
207 }
208 return x, nil
209}
67func clientStream(c pb.GripmockClient, wg *sync.WaitGroup) {
68 defer wg.Done()
69 stream, err := c.ClientStream(context.Background())
70 if err != nil {
71 log.Fatalf("c2s error: %v", err)
72 }
73
74 requests := []pb.Request{
75 {
76 Name: "c2s-1",
77 }, {
78 Name: "c2s-2",
79 },
80 }
81 for _, req := range requests {
82 err := stream.Send(&req)
83 if err != nil {
84 log.Fatalf("c2s error: %v", err)
85 }
86 }
87 reply, err := stream.CloseAndRecv()
88 if err != nil {
89 log.Fatalf("c2s error: %v", err)
90 }
91
92 log.Printf("c2s message: %v", reply.Message)
93}
56func (srv *Server) StreamEvent1(req *reflexpb.StreamRequest, ss pb.ExServer_StreamEvent1Server) error {
57 return srv.rserver.Stream(srv.events1StreamFunc, req, ss)
58}
277func streamingCmdExists(data []*commandData) bool {
278 for _, c := range data {
279 if c.NeedStream {
280 return true
281 }
282 }
283 return false
284}

Related snippets