commit 64fa15d571efe19d8de9d2a9e303f3c46c2a8559 Author: Charles Iliya Krempeaux Date: Mon Aug 14 21:39:31 2023 -0700 initial commits diff --git a/rootdir.go b/rootdir.go new file mode 100644 index 0000000..520f3e2 --- /dev/null +++ b/rootdir.go @@ -0,0 +1,58 @@ +package maymoon + +import ( + "fmt" + "os" + "path/filepath" +) +const ( + publicRootDirName string = "public_root" + publicRootEnvName string = "PUBLIC_ROOT" +) + +// RootDir returns the "root" directory. +// +// By default, where the "root" directory is depends which user it is running under. +// +// For example, on a Unix or Unix-like system such as Linux, with a user "joeblow" who has a home-directory at +// "/home/joeblow", RootDir might return "/home/joeblow/public_root". +// +// This can be overridden using the "PUBLIC_ROOT" environment variable. +// For example: +// +// PUBLIC_ROOT=/path/to/public_root +// +// Example usage: +// +// rootDir, err := maymoon.RootDir() +// if nil != err { +// return err +// } +// +// fmt.Printf("The maymoon root-dir is at %q \n", rootDir) +func RootDir() (string, error) { + + var path string + + { + path = os.Getenv(publicRootEnvName) + if "" != path { +/////////////////////// RETURN + return path, nil + } + } + + { + homedir, err := os.UserHomeDir() + if nil != err { + return "", fmt.Errorf("problem getting user home-directory: %s", err) + } + + path := filepath.Join(homedir, publicRootDirName) + if "" != path { + return path, nil + } + } + + return "", nil +}