Add os specific stuff
This commit is contained in:
parent
ff4b332abc
commit
e9cbf8bf28
|
@ -0,0 +1,22 @@
|
||||||
|
//go:build darwin
|
||||||
|
// +build darwin
|
||||||
|
|
||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/user"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IsSuperUser returns true, if the current user is a super user
|
||||||
|
// A.K.A root, Administrator etc
|
||||||
|
func IsSuperUser() bool {
|
||||||
|
cuser, err := user.Current()
|
||||||
|
return err == nil && "0" == cuser.Uid
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGlobalConfigurationDirectory returns OS specific location for putting
|
||||||
|
// global configuration files
|
||||||
|
func GetGlobalConfigurationDirectory(appname string) string {
|
||||||
|
return filepath.Join("/etc", appname)
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
//go:build linux
|
||||||
|
// +build linux
|
||||||
|
|
||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/user"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IsSuperUser returns true, if the current user is a super user
|
||||||
|
// A.K.A root, Administrator etc
|
||||||
|
func IsSuperUser() bool {
|
||||||
|
cuser, err := user.Current()
|
||||||
|
return err == nil && "0" == cuser.Uid
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGlobalConfigurationDirectory returns OS specific location for putting
|
||||||
|
// global configuration files
|
||||||
|
func GetGlobalConfigurationDirectory(appname string) string {
|
||||||
|
return filepath.Join("/etc", appname)
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
//go:build windows
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IsSuperUser returns true, if the current user is a super user
|
||||||
|
// A.K.A root, Administrator etc
|
||||||
|
func IsSuperUser() bool {
|
||||||
|
_, err := os.Open("\\\\.\\PHYSICALDRIVE0")
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGlobalConfigurationDirectory returns OS specific location for putting
|
||||||
|
// global configuration files
|
||||||
|
func GetGlobalConfigurationDirectory(appname string) string {
|
||||||
|
return filepath.Join(os.Getenv("APPDATA"), appname)
|
||||||
|
}
|
Loading…
Reference in New Issue