Config Tweaks

Using viper for config management.  Added configuration endpoint.
This commit is contained in:
Stash Dev
2019-03-23 07:56:59 -07:00
parent b69739dcc4
commit dd22d88d07
45 changed files with 940 additions and 642 deletions

View File

@@ -1,6 +1,7 @@
package utils
import (
"fmt"
"github.com/h2non/filetype"
"github.com/h2non/filetype/types"
"os"
@@ -28,6 +29,27 @@ func FileExists(path string) (bool, error) {
}
}
func DirExists(path string) (bool, error) {
exists, _ := FileExists(path)
fileInfo, _ := os.Stat(path)
if !exists || !fileInfo.IsDir() {
return false, fmt.Errorf("path either doesn't exist, or is not a directory <%s>", path)
}
return true, nil
}
func Touch(path string) error {
var _, err = os.Stat(path)
if os.IsNotExist(err) {
var file, err = os.Create(path)
if err != nil {
return err
}
defer file.Close()
}
return nil
}
func EnsureDir(path string) error {
exists, err := FileExists(path)
if !exists {