func streamStreamOut(conn connection.Connection) { for { payload := &warden.StreamChunk{} err := conn.ReadResponse(payload) if err != nil { fmt.Println("stream failed:", err) os.Exit(1) } os.Stdout.Write(payload.GetContent()) if payload.EOF != nil { break } } }
func streamProcessPayloads(conn connection.Connection, encoder *json.Encoder) { for { payload := &warden.ProcessPayload{} err := conn.ReadResponse(payload) if err != nil { fmt.Println("stream failed:", err) os.Exit(1) } encoder.Encode(payload) if payload.ExitStatus != nil { break } } }
func streamStreamIn(conn connection.Connection) { for { buf := make([]byte, 64*1024) n, err := os.Stdin.Read(buf) if n > 0 { err := conn.SendMessage(&warden.StreamChunk{ Content: buf[:n], }) if err != nil { fmt.Println("writing content failed:", err) os.Exit(1) } } if err == io.EOF { err := conn.SendMessage(&warden.StreamChunk{ EOF: proto.Bool(true), }) if err != nil { fmt.Println("writing EOF failed:", err) os.Exit(1) } break } if err != nil { fmt.Println("stream interrupted:", err) os.Exit(1) } } resp := &warden.StreamInResponse{} err := conn.ReadResponse(resp) if err != nil { fmt.Println("stream failed:", err) os.Exit(1) } }