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 var conns []*client.Conn
54 for i := 0; i < 10; i++ {
55 conn, err := client.Connect(*addr, *user)
56 if err != nil {
57 fatalf("Failed to connect to SysDB at %q: %v", *addr, err)
58 }
59 conns = append(conns, conn)
60 }
62 srv, err := server.New(server.Config{
63 Conns: conns,
64 TemplatePath: *tmpl,
65 StaticPath: *static,
66 })
67 if err != nil {
68 fatalf("Failed to construct web-server: %v", err)
69 }
71 log.Printf("Listening on %s.", *listen)
72 http.Handle("/", srv)
73 err = http.ListenAndServe(*listen, nil)
74 if err != nil {
75 fatalf("Failed to set up HTTP server on address %q: %v", *listen, err)
76 }
77 }
79 func fatalf(format string, a ...interface{}) {
80 fmt.Fprintf(os.Stderr, format, a...)
81 fmt.Fprintln(os.Stderr)
82 os.Exit(1)
83 }
85 // vim: set tw=78 sw=4 sw=4 noexpandtab :