gonextcloud/vendor/github.com/partitio/swarmmanager/libnextcloudpartitio/utils/utils.go
2018-10-08 18:50:11 +02:00

46 lines
709 B
Go

package utils
import (
"bytes"
"encoding/json"
"fmt"
"io"
"os"
)
func PrettyPrint(v interface{}) (err error) {
b, err := json.MarshalIndent(v, "", " ")
if err == nil {
fmt.Println(string(b))
}
return
}
func FileCopy(src string, dst string) error {
from, err := os.Open(src)
if err != nil {
return err
}
defer from.Close()
to, err := os.OpenFile(dst, os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
return err
}
defer to.Close()
_, err = io.Copy(to, from)
if err != nil {
return err
}
return nil
}
func StreamToString(stream io.Reader) (string, error) {
buf := new(bytes.Buffer)
if _, err := buf.ReadFrom(stream); err != nil {
return "", err
}
return buf.String(), nil
}