mark2web/pkg/helper/dir.go
Sebastian Frank a17926f54b
logger pkg
2019-03-25 09:28:58 +01:00

29 lines
785 B
Go

package helper
import (
"os"
"gitbase.de/apairon/mark2web/pkg/logger"
)
// CreateDirectory creates direcory with all missing parents and panic if error
func CreateDirectory(dir string) {
logger.Log.Debugf("trying to create output directory: %s", dir)
if dirH, err := os.Stat(dir); os.IsNotExist(err) {
err := os.MkdirAll(dir, 0755)
if err != nil {
logger.Log.Panicf("could not create output directory '%s': %s", dir, err)
}
logger.Log.Noticef("created output directory: %s", dir)
} else if dirH != nil {
if dirH.IsDir() {
logger.Log.Noticef("output directory '%s' already exists", dir)
} else {
logger.Log.Panicf("output directory '%s' is no directory", dir)
}
} else {
logger.Log.Panicf("unknown error for output directory '%s': %s", dir, err)
}
}