initial commits
commit
64fa15d571
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue