-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
58 lines (50 loc) · 1.06 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package maimok
import (
"fmt"
"net/http"
"os"
"text/template"
libvirt "github.com/libvirt/libvirt-go"
)
type globalState struct {
config *Config
conn *libvirt.Connect
tpl *template.Template
}
// Run is the main entry point
func Run() {
code := 0
defer func() {
os.Exit(code)
}()
// load config file
config, err := LoadConfig()
if err != nil {
fmt.Printf("Cannot load configuration file: %s\n", err)
code = 1
return
}
// load templates
templates, err := template.ParseGlob("templates/*")
if err != nil {
fmt.Printf("Cannot load template files: %s\n", err)
code = 1
return
}
// connect to hypervisor
connection, err := libvirt.NewConnect(config.LibvirtURL)
defer connection.Close()
if err != nil {
fmt.Printf("Cannot connect to libvirtd with URL %s, %s\n", config.LibvirtURL, err)
code = 1
return
}
state := globalState{conn: connection, config: config, tpl: templates}
fmt.Println("Starting server on port 7000")
err = http.ListenAndServe(":7000", GetRouter(&state))
if err != nil {
fmt.Println(err)
code = 1
return
}
}