Improve core module to take care of dir structures and db init

This commit is contained in:
Daniel
2019-07-31 22:34:23 +02:00
parent 82026cd7d9
commit 7a6189143c
5 changed files with 169 additions and 10 deletions

27
core/structure/dirs.go Normal file
View File

@@ -0,0 +1,27 @@
package structure
import (
"os"
"github.com/safing/portbase/utils"
)
var (
root *utils.DirStructure
)
// Initialize initializes the data root directory
func Initialize(rootDir string, perm os.FileMode) error {
root = utils.NewDirStructure(rootDir, perm)
return root.Ensure()
}
// Root returns the data root directory.
func Root() *utils.DirStructure {
return root
}
// NewRootDir calls ChildDir() on the data root directory.
func NewRootDir(dirName string, perm os.FileMode) (childDir *utils.DirStructure) {
return root.ChildDir(dirName, perm)
}