-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c09f241
commit 8961441
Showing
9 changed files
with
106 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package helpers | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os/exec" | ||
"os/user" | ||
) | ||
|
||
func AsJSONString(i interface{}) string { | ||
bytes, err := json.Marshal(i) | ||
if err != nil { | ||
return fmt.Sprintf("ERROR: AsJSONString(), details [%s]", err.Error()) | ||
} | ||
return string(bytes) | ||
} | ||
|
||
func Is(err1 error, err2 error) bool { | ||
if err1 == err2 { | ||
return true | ||
} | ||
|
||
if err1 != nil && err2 != nil { | ||
return err1.Error() == err2.Error() | ||
} | ||
|
||
return false | ||
} | ||
|
||
func ExecWithArgs(name string, args ...string) (out string, err error) { | ||
output, err := exec.Command(name, args...).CombinedOutput() | ||
return string(output), err | ||
} | ||
|
||
|
||
func IsRoot() bool { | ||
u, err := user.Current() | ||
|
||
if err != nil { | ||
return false | ||
} | ||
|
||
// On unix systems, root user either has the UID 0, | ||
// the GID 0 or both. | ||
return u.Uid == "0" || u.Gid == "0" | ||
} | ||
|
||
func HomeDir(returnIfError string) string { | ||
u, err := user.Current() | ||
if err != nil { | ||
return returnIfError | ||
} | ||
|
||
return u.HomeDir | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.