1 //
2 // Copyright (C) 2014 Sebastian 'tokkee' Harl <sh@tokkee.org>
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions
7 // are met:
8 // 1. Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // 2. Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 // ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
16 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
18 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // webui is a web-based user-interface for SysDB.
27 package main
29 import (
30 "flag"
31 "fmt"
32 "log"
33 "net/http"
34 "os"
36 "github.com/sysdb/go/client"
37 "github.com/sysdb/webui/server"
38 )
40 var (
41 addr = flag.String("address", "/var/run/sysdbd.sock", "SysDB server address")
42 user = flag.String("user", "sysdb", "SysDB user name")
44 listen = flag.String("listen", ":8080", "address to listen for incoming connections")
45 tmpl = flag.String("template-path", "templates", "location of template files")
46 static = flag.String("static-path", "static", "location of static files")
47 )
49 func main() {
50 flag.Parse()
52 log.Printf("Connecting to SysDB at %s.", *addr)
53 conn, err := client.Connect(*addr, *user)
54 if err != nil {
55 fatalf("Failed to connect to SysDB at %q: %v", *addr, err)
56 }
58 srv, err := server.New(server.Config{
59 Conn: conn,
60 TemplatePath: *tmpl,
61 StaticPath: *static,
62 })
63 if err != nil {
64 fatalf("Failed to construct web-server: %v", err)
65 }
67 log.Printf("Listening on %s.", *listen)
68 http.Handle("/", srv)
69 err = http.ListenAndServe(*listen, nil)
70 if err != nil {
71 fatalf("Failed to set up HTTP server on address %q: %v", *listen, err)
72 }
73 }
75 func fatalf(format string, a ...interface{}) {
76 fmt.Fprintf(os.Stderr, format, a...)
77 fmt.Fprintln(os.Stderr)
78 os.Exit(1)
79 }
81 // vim: set tw=78 sw=4 sw=4 noexpandtab :