io: move common function and add unit tests for it
This commit is contained in:
parent
11ce73af28
commit
d799c98cfe
4 changed files with 61 additions and 17 deletions
18
pkg/io/fileWriter.go
Normal file
18
pkg/io/fileWriter.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
package io
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
// MakeDirForFile creates directory provided in filePath.
|
||||
func MakeDirForFile(filePath string, creator string) error {
|
||||
fileName := filePath
|
||||
dir := path.Dir(fileName)
|
||||
err := os.MkdirAll(dir, os.ModePerm)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create dir for %s: %v", creator, err)
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue