aboutsummaryrefslogtreecommitdiff
path: root/takeoff.go
diff options
context:
space:
mode:
Diffstat (limited to 'takeoff.go')
-rw-r--r--takeoff.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/takeoff.go b/takeoff.go
new file mode 100644
index 0000000..7f7dd09
--- /dev/null
+++ b/takeoff.go
@@ -0,0 +1,62 @@
+package main
+
+import (
+ "flag"
+ "html/template"
+ "log"
+ "net/http"
+ "path"
+)
+
+var (
+ addr = flag.String("a", "localhost:8888", "listen address")
+ cdir = flag.String("c", "config", "path to configuration directory")
+ sdir = flag.String("s", "static", "path to static files directory")
+ tdir = flag.String("t", "templates", "path to templates directory")
+)
+
+var (
+ instances *lineListConfig
+ langs *langListConfig
+)
+
+var homeTemplate string
+
+var tData struct {
+ Instances []string
+ Langs []Lang
+}
+
+func home(w http.ResponseWriter, r *http.Request) {
+ tData.Instances = instances.getList()
+ tData.Langs = langs.getList()
+ t := template.Must(template.ParseFiles(homeTemplate))
+ t.Execute(w, &tData)
+}
+
+func serve() {
+ files := http.FileServer(http.Dir(*sdir))
+ http.HandleFunc("/", home)
+ http.Handle("/static/", http.StripPrefix("/static/", files))
+ log.Fatal(http.ListenAndServe(*addr, nil))
+}
+
+func main() {
+ var err error
+
+ flag.Parse()
+
+ startConfigWatcher(*cdir)
+ defer stopConfigWatcher()
+
+ instances, err = newLineListConfig("instances")
+ langs, err = newLangListConfig("langs")
+ if err != nil {
+ log.Fatal("FATAL: config list error: ", err)
+ }
+
+ homeTemplate = path.Join(*tdir, "index.html")
+
+ log.Printf("takeoff v0 listening at http://%s\n", *addr)
+ serve()
+}