Restructured to have subpackages, added server communication

This commit is contained in:
2013-02-20 23:43:01 -05:00
parent b193814371
commit 3fc3e3a963
10 changed files with 201 additions and 35 deletions

44
util/util.go Normal file
View File

@ -0,0 +1,44 @@
package util
import (
"io"
"io/ioutil"
"os"
"path"
)
func EnsureDirExists(dir string) error {
_, err := os.Lstat(dir)
if err != nil {
fi, err := os.Lstat(path.Dir(dir))
if err != nil {
return err
}
err = os.Mkdir(dir, fi.Mode().Perm())
if err != nil {
return err
}
}
return nil
}
func CopyToTmp(src string, tmpdir string) (string, error) {
infile, err := os.Open(src)
if err != nil {
return "", err
}
defer infile.Close()
outfile, err := ioutil.TempFile(tmpdir, "asink")
if err != nil {
return "", err
}
defer outfile.Close()
_, err = io.Copy(outfile, infile)
if err != nil {
return "", err
}
return outfile.Name(), nil
}