Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
570 B

package Util
import (
"fmt"
"os"
)
// WriteFile to disk
func WriteFile(contents []byte) (string, error) {
var (
fileName string
filePath string
cwd string
f *os.File
err error
)
cwd, err = os.Getwd()
if err != nil {
return fileName, err
}
fileName = RandomString(32)
filePath = fmt.Sprintf(
"%s/attachments/%s",
cwd,
fileName,
)
f, err = os.Create(filePath)
if err != nil {
return fileName, err
}
defer f.Close()
_, err = f.Write(contents)
if err != nil {
return fileName, err
}
return fileName, nil
}