generated from VLADIMIR/template
add parser
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const (
|
||||
ClientPort = ":8100"
|
||||
FilePort = ":8120"
|
||||
)
|
||||
|
||||
func GetScheduleFilepath() string {
|
||||
return getFilepath("SCHEDULE_FILENAME", "data/schedule.json")
|
||||
}
|
||||
|
||||
func getFilepath(env string, defaultFilepath string) string {
|
||||
filepath := selectFilepath(env, defaultFilepath)
|
||||
ensureDirExists(filepath)
|
||||
return filepath
|
||||
}
|
||||
|
||||
func selectFilepath(env string, defaultFilepath string) string {
|
||||
filepath := os.Getenv(env)
|
||||
if filepath != "" {
|
||||
return filepath
|
||||
}
|
||||
return defaultFilepath
|
||||
}
|
||||
|
||||
func ensureDirExists(filePath string) error {
|
||||
dir := filepath.Dir(filePath)
|
||||
if dir == "" || dir == "." || dir == "/" {
|
||||
return nil
|
||||
}
|
||||
return os.MkdirAll(dir, 0755)
|
||||
}
|
||||
Reference in New Issue
Block a user