preparing sj.mcquay.me flags for launchd
This commit is contained in:
parent
ca118d0638
commit
9038110f09
14
main.go
14
main.go
@ -6,6 +6,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
@ -22,10 +23,11 @@ var m = sync.Mutex{}
|
|||||||
var addr = flag.String("addr", ":8000", "http service address")
|
var addr = flag.String("addr", ":8000", "http service address")
|
||||||
var static_files = flag.String("static", "./static", "location of static files")
|
var static_files = flag.String("static", "./static", "location of static files")
|
||||||
var db_file = flag.String("db", "db.json", "output database")
|
var db_file = flag.String("db", "db.json", "output database")
|
||||||
var homeTempl = template.Must(template.ParseFiles("index.html"))
|
var template_dir = flag.String("templates", "templates", "template dir")
|
||||||
|
var templates *template.Template
|
||||||
|
|
||||||
func homeHandler(c http.ResponseWriter, req *http.Request) {
|
func homeHandler(c http.ResponseWriter, req *http.Request) {
|
||||||
homeTempl.Execute(c, req.Host)
|
templates.Execute(c, req.Host)
|
||||||
}
|
}
|
||||||
|
|
||||||
func passHandler(resp http.ResponseWriter, req *http.Request) {
|
func passHandler(resp http.ResponseWriter, req *http.Request) {
|
||||||
@ -69,6 +71,14 @@ func init_db() {
|
|||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
init_db()
|
init_db()
|
||||||
|
pattern := filepath.Join(*template_dir, "*.html")
|
||||||
|
var err error
|
||||||
|
templates, err = template.ParseGlob(pattern)
|
||||||
|
if err != nil {
|
||||||
|
println(*template_dir)
|
||||||
|
println(pattern)
|
||||||
|
log.Fatal("problem parsing template dir:", *template_dir)
|
||||||
|
}
|
||||||
http.HandleFunc("/", homeHandler)
|
http.HandleFunc("/", homeHandler)
|
||||||
http.HandleFunc("/pass", passHandler)
|
http.HandleFunc("/pass", passHandler)
|
||||||
http.HandleFunc("/api/1.0/creds/", credHandler)
|
http.HandleFunc("/api/1.0/creds/", credHandler)
|
||||||
|
Loading…
Reference in New Issue
Block a user