gorm-goose/lib/goose/util.go

41 lines
567 B
Go
Raw Normal View History

2016-09-09 14:12:30 +02:00
package goose
import (
"io"
"os"
"text/template"
)
// common routines
func writeTemplateToFile(path string, t *template.Template, data interface{}) (string, error) {
f, e := os.Create(path)
if e != nil {
return "", e
}
defer f.Close()
e = t.Execute(f, data)
if e != nil {
return "", e
}
return f.Name(), nil
}
func copyFile(dst, src string) (int64, error) {
sf, err := os.Open(src)
if err != nil {
return 0, err
}
defer sf.Close()
df, err := os.Create(dst)
if err != nil {
return 0, err
}
defer df.Close()
return io.Copy(df, sf)
}