From 5a11074ae6d21839b99b9def7068f7aff2ab8f87 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Tue, 23 Dec 2014 13:03:27 +0100 Subject: [PATCH] Use the current username by default. --- main.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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) } -- 2.30.2