Code

Use the current username by default.
authorSebastian Harl <sh@tokkee.org>
Tue, 23 Dec 2014 12:03:27 +0000 (13:03 +0100)
committerSebastian Harl <sh@tokkee.org>
Tue, 23 Dec 2014 12:03:27 +0000 (13:03 +0100)
main.go

diff --git a/main.go b/main.go
index 20bb7322b10beb6dd94b849c1a0c26f7b802581f..e74ec554648a5c4ed974b2eab9842a78f793a005 100644 (file)
--- 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)
                }