add livelog copy function

pull/1/head
Brad Rydzewski 5 years ago
parent c0d9268011
commit e458a51996

@ -0,0 +1,38 @@
// Copyright 2019 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Polyform License
// that can be found in the LICENSE file.
package livelog
import (
"bufio"
"io"
)
// Copy copies from src to dst and removes until either EOF
// is reached on src or an error occurs.
func Copy(dst io.Writer, src io.ReadCloser) error {
r := bufio.NewReader(src)
for {
bytes, err := r.ReadBytes('\n')
if _, err := dst.Write(bytes); err != nil {
return err
}
if flusher, ok := dst.(Flusher); ok {
flusher.Flush()
}
if err != nil {
if err != io.EOF {
return err
}
return nil
}
}
}
// The Flusher interface is implemented by an io.Writer that
// flushes buffered data to the client.
type Flusher interface {
// Flush sends any buffered data to the client.
Flush() error
}

@ -0,0 +1,5 @@
// Copyright 2019 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Polyform License
// that can be found in the LICENSE file.
package livelog

@ -13,7 +13,7 @@ type (
Secret string `json:"from_secret,omitempty" yaml:"from_secret"`
}
// variable is a tempoary type used to unmarshal
// variable is a temporary type used to unmarshal
// variables with references to secrets.
variable struct {
Value string

Loading…
Cancel
Save