Skip to content

Commit

Permalink
pkg/template: reformat the template function for current username
Browse files Browse the repository at this point in the history
  • Loading branch information
tmrts committed Jul 19, 2017
1 parent bedb26e commit 8f51ad7
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions pkg/template/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package template
import (
"fmt"
"os"
"os/user"
"reflect"
"strconv"
"strings"
"text/template"
"time"
"os/user"
)

var (
Expand All @@ -23,8 +23,14 @@ var (
"env": os.Getenv,
"time": CurrentTimeInFmt,
"hostname": func() string { return os.Getenv("HOSTNAME") },
"username": UserName,
"username": func() string {
t, err := user.Current()
if err != nil {
return "Unknown"
}

return t.Name
},
"toBinary": func(s string) string {
n, err := strconv.Atoi(s)
if err != nil {
Expand Down Expand Up @@ -104,13 +110,3 @@ 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 comments on commit 8f51ad7

Please sign in to comment.