mirror of
https://gitlab.bertha.cloud/partitio/Nextcloud-Partitio/gonextcloud
synced 2024-11-15 09:46:25 +00:00
46 lines
709 B
Go
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
|
|
}
|