Skip to content
Snippets Groups Projects
Commit 5958eae1 authored by nimrod's avatar nimrod
Browse files

Added username template function.

parent cbb813e7
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ import (
"strings"
"text/template"
"time"
"os/user"
)
var (
......@@ -22,6 +23,7 @@ var (
"env": os.Getenv,
"time": CurrentTimeInFmt,
"hostname": func() string { return os.Getenv("HOSTNAME") },
"username": UserName,
"toBinary": func(s string) string {
n, err := strconv.Atoi(s)
......@@ -100,3 +102,13 @@ func CurrentTimeInFmt(fmt string) string {
return t.Format(fmt)
}
// UserName returns the user's name (not the login name).
func UserName() string {
t, err := user.Current();
if ( err != nil ) {
return "Unknown";
}
return t.Name;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment