From: Sebastian Harl Date: Tue, 23 Dec 2014 12:03:27 +0000 (+0100) Subject: Use the current username by default. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5a11074ae6d21839b99b9def7068f7aff2ab8f87;p=sysdb%2Fwebui.git Use the current username by default. --- diff --git a/main.go b/main.go index 20bb732..e74ec55 100644 --- a/main.go +++ b/main.go @@ -32,27 +32,40 @@ import ( "log" "net/http" "os" + "os/user" "github.com/sysdb/go/client" "github.com/sysdb/webui/server" ) var ( - addr = flag.String("address", "/var/run/sysdbd.sock", "SysDB server address") - user = flag.String("user", "sysdb", "SysDB user name") + addr = flag.String("address", "/var/run/sysdbd.sock", "SysDB server address") + username *string listen = flag.String("listen", ":8080", "address to listen for incoming connections") tmpl = flag.String("template-path", "templates", "location of template files") static = flag.String("static-path", "static", "location of static files") ) +func init() { + u, err := user.Current() + var def string + if err != nil { + log.Printf("WARNING: Unable to determine current user: %v", err) + } else { + def = u.Username + } + + username = flag.String("user", def, "SysDB user name") +} + func main() { flag.Parse() log.Printf("Connecting to SysDB at %s.", *addr) var conns []*client.Conn for i := 0; i < 10; i++ { - conn, err := client.Connect(*addr, *user) + conn, err := client.Connect(*addr, *username) if err != nil { fatalf("Failed to connect to SysDB at %q: %v", *addr, err) }