no need to use templates

This commit is contained in:
Stephen McQuay 2015-05-25 16:54:44 -07:00
parent 96e4a101d8
commit 5f4b24ba35
6 changed files with 26 additions and 52 deletions

View File

@ -6,4 +6,3 @@ import (
var addr = flag.String("addr", ":8000", "http service address")
var db_file = flag.String("db", "db.json", "output database")
var template_dir = flag.String("templates", "templates", "template dir")

View File

@ -7,21 +7,6 @@ import (
"net/http"
)
func homeHandler(c http.ResponseWriter, req *http.Request) {
log.Printf("%v\n", req.URL)
t := templates.Lookup("index.html")
if t != nil {
t.Execute(c, req.Host)
} else {
log.Fatal("template index.html not found")
}
}
func helloHandler(c http.ResponseWriter, req *http.Request) {
t := templates.Lookup("hello.html")
t.Execute(c, req.Host)
}
func passHandler(resp http.ResponseWriter, req *http.Request) {
un := req.FormValue("username")
pw := req.FormValue("password")

16
main.go
View File

@ -8,7 +8,6 @@ import (
"log"
"net/http"
"os"
"path/filepath"
"sync"
"github.com/elazarl/go-bindata-assetfs"
@ -38,16 +37,7 @@ func init_db() {
func main() {
flag.Parse()
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("/hello/", helloHandler)
http.HandleFunc("/pass", passHandler)
http.HandleFunc("/api/1.0/creds/", credHandler)
@ -64,8 +54,8 @@ func main() {
fs = http.Dir(os.Getenv("DEV"))
}
http.Handle("/s/", http.StripPrefix("/s/",
http.FileServer(fs)))
http.Handle("/", http.RedirectHandler("/s/", http.StatusMovedPermanently))
http.Handle("/s/", http.StripPrefix("/s/", http.FileServer(fs)))
if err := http.ListenAndServe(*addr, nil); err != nil {
log.Fatal("ListenAndServe:", err)

View File

@ -221,6 +221,26 @@ func static_bootstrap_js_bootstrap_min_js() (*asset, error) {
return a, nil
}
var _static_index_html = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xbc\x54\x41\x73\xdb\x2c\x10\xbd\xe7\x57\xf0\x71\xfe\x24\x9c\xb6\xa7\x54\xf2\x25\xed\xb9\x9d\x49\x2f\x3d\x62\x58\x47\x38\x88\xa5\xb0\xb6\xe3\xe9\xf4\xbf\x17\x50\x6d\xcb\x4a\xad\x99\x74\x3a\xd5\xc5\xec\xf2\xf6\x3d\xf6\x81\xb7\xf9\xef\xc3\xa7\xfb\x2f\x5f\x3f\x7f\x64\x1d\xf5\x76\x79\xd3\x0c\x3f\x2c\x7d\x4d\x07\x52\x0f\xcb\x12\x92\x21\x0b\xcb\x7b\xec\x8d\x7b\x64\x0f\x88\xae\xae\xeb\x46\x0c\xd9\x33\xaa\x07\x92\xcc\xc9\x1e\x5a\xbe\x33\xb0\xf7\x18\x88\x33\x85\x8e\xc0\x51\xcb\xf7\x46\x53\xd7\x6a\xd8\x19\x05\x55\x09\xfe\x67\xc6\x19\x32\xd2\x56\x51\x49\x0b\xed\x6d\xbd\xe0\x23\x3a\x6b\xdc\x13\xeb\x02\xac\x5b\x2e\xa2\x58\x21\x52\xa4\x20\xbd\x50\x71\x14\xd5\xe9\x48\x75\xca\x70\x16\xc0\xb6\x3c\xd2\xc1\x42\xec\x00\x92\x72\x0f\xda\xc8\x94\x52\x01\xc0\xbd\x9a\xb8\x0a\x10\x3d\xba\x68\x76\xf0\x27\x1a\x05\x74\x8e\xf3\x57\xfb\x3d\xfb\x7e\x91\xc9\x9f\x97\x5a\x27\x57\x2b\x42\x7f\xc7\x6e\x17\x0b\xff\xfc\xfe\x02\xf3\xe3\xcc\x29\x46\xa4\x8d\x38\x5f\x51\xb3\x42\x7d\x18\x69\x6b\xb3\x63\xca\xca\x18\x5b\x9e\xdd\x97\xc6\x41\x60\x7e\xcf\x2f\x8f\x33\x86\x05\x9c\xee\x16\xc4\x1a\x43\x7f\x84\x94\x35\xae\xd7\x11\xe8\x1d\x8b\x5e\xba\xb7\xb9\x7b\xea\x50\xb7\xdc\x63\x4c\x5e\x48\x45\x06\x5d\xf2\xd4\xa7\x82\xdf\xd0\x4d\x45\x8d\xf3\x5b\xaa\x7c\x00\x0f\x4e\x17\xca\x37\x57\xaa\x06\x47\x13\xe0\x58\x9a\x3c\xab\xd0\xcd\xa0\x4b\x85\x39\x29\x25\x1b\xaa\x6d\x84\xc0\x97\x8d\x30\x33\x1a\x22\x8b\xcc\xec\x97\x23\x33\x3a\xf8\xf4\xc4\x09\x9e\x53\xd3\xc3\x73\xcf\xdc\x79\xc5\x99\xb7\x52\x41\x87\x56\x43\x18\xa5\xc5\x15\x37\x44\xb2\x63\x79\xf3\x4a\xa7\x86\x48\xfa\x7f\x63\x9b\x45\xf5\xf4\x37\x6d\xcb\x8f\x63\x8f\x41\xf3\xa3\xca\xd1\xc3\xf3\xc6\x85\x87\xa7\x74\x3e\x43\xe6\x99\xd1\x59\x6d\x89\xf0\xd4\xed\x8a\x1c\xff\x25\x1a\xb7\xab\xde\x10\x5f\x3e\x98\x47\x97\xfc\x6b\xc4\x80\x9c\xbd\x95\x97\xe9\xfc\x17\x98\xdc\xd6\x04\x3b\x0d\xd3\x5c\x30\x9e\x58\x0c\xaa\xe5\x1d\x91\xbf\x13\x42\xa1\x86\x7a\xf3\x6d\x0b\xe1\x50\x2b\xec\xc5\xb0\xac\xac\x24\x88\x54\x6f\x62\xee\x73\x28\xbb\xc2\x73\x31\xb2\x36\xd3\x51\xf8\x92\x20\x35\x5b\xc6\x43\x9a\x18\x65\xbe\xff\x0c\x00\x00\xff\xff\xf3\x58\x5a\x13\xf7\x05\x00\x00")
func static_index_html_bytes() ([]byte, error) {
return bindata_read(
_static_index_html,
"static/index.html",
)
}
func static_index_html() (*asset, error) {
bytes, err := static_index_html_bytes()
if err != nil {
return nil, err
}
info := bindata_file_info{name: "static/index.html", size: 1527, mode: os.FileMode(436), modTime: time.Unix(1430190034, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
// Asset loads and returns the asset for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
@ -270,6 +290,7 @@ var _bindata = map[string]func() (*asset, error){
"static/bootstrap/img/glyphicons-halflings.png": static_bootstrap_img_glyphicons_halflings_png,
"static/bootstrap/js/bootstrap.js": static_bootstrap_js_bootstrap_js,
"static/bootstrap/js/bootstrap.min.js": static_bootstrap_js_bootstrap_min_js,
"static/index.html": static_index_html,
}
// AssetDir returns the file names below a certain
@ -337,6 +358,8 @@ var _bintree = &_bintree_t{nil, map[string]*_bintree_t{
}},
}},
}},
"index.html": &_bintree_t{static_index_html, map[string]*_bintree_t{
}},
}},
}}

View File

@ -1,23 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Coming Soon...</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="/s/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="/s/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
<style>
.pw {
padding-top: 100px;
}
</style>
</head>
<body>
<div class="container pw">
<div class="row">
<button class="btn offset4 span3" type="submit">wat</button>
</div>
</div>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="/s/bootstrap/js/bootstrap.min.js"></script>
</body>
</html>