Compare commits
1
Commits
embed-assets
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2390ee9bf2 |
@@ -5,4 +5,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var addr = flag.String("addr", ":8000", "http service address")
|
var addr = flag.String("addr", ":8000", "http service address")
|
||||||
var dbFile = flag.String("db", "db.json", "output database")
|
var static_files = flag.String("static", "./static", "location of static files")
|
||||||
|
var db_file = flag.String("db", "db.json", "output database")
|
||||||
|
var template_dir = flag.String("templates", "templates", "template dir")
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
//go:generate go get github.com/jteeuwen/go-bindata/...
|
|
||||||
//go:generate go get github.com/elazarl/go-bindata-assetfs/...
|
|
||||||
//go:generate rm -f static.go
|
|
||||||
//go:generate go-bindata -o static.go -pkg=main static/...
|
|
||||||
+16
-1
@@ -7,6 +7,21 @@ import (
|
|||||||
"net/http"
|
"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) {
|
func passHandler(resp http.ResponseWriter, req *http.Request) {
|
||||||
un := req.FormValue("username")
|
un := req.FormValue("username")
|
||||||
pw := req.FormValue("password")
|
pw := req.FormValue("password")
|
||||||
@@ -18,7 +33,7 @@ func passHandler(resp http.ResponseWriter, req *http.Request) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
err = ioutil.WriteFile(*dbFile, b, 0644)
|
err = ioutil.WriteFile(*db_file, b, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
Copyright (c) 2015, stephen mcquay
|
||||||
|
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
* Neither the name of credgrabber nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this software
|
||||||
|
without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
@@ -7,10 +7,8 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/elazarl/go-bindata-assetfs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Cred struct {
|
type Cred struct {
|
||||||
@@ -22,8 +20,8 @@ var creds = make([]Cred, 0)
|
|||||||
var m = sync.Mutex{}
|
var m = sync.Mutex{}
|
||||||
var templates *template.Template
|
var templates *template.Template
|
||||||
|
|
||||||
func initDb() {
|
func init_db() {
|
||||||
b, err := ioutil.ReadFile(*dbFile)
|
b, err := ioutil.ReadFile(*db_file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Problem opening db file ... ignoring ...", err)
|
log.Println("Problem opening db file ... ignoring ...", err)
|
||||||
}
|
}
|
||||||
@@ -36,27 +34,21 @@ func initDb() {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
initDb()
|
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("/pass", passHandler)
|
||||||
http.HandleFunc("/api/1.0/creds/", credHandler)
|
http.HandleFunc("/api/1.0/creds/", credHandler)
|
||||||
|
http.Handle("/s/", http.StripPrefix("/s/",
|
||||||
var fs http.FileSystem
|
http.FileServer(http.Dir(*static_files))))
|
||||||
if os.Getenv("DEV") == "" {
|
|
||||||
log.Printf("static: prod mode")
|
|
||||||
fs = &assetfs.AssetFS{
|
|
||||||
Asset: Asset,
|
|
||||||
AssetDir: AssetDir,
|
|
||||||
Prefix: "static",
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.Printf("static: dev mode")
|
|
||||||
fs = http.Dir(os.Getenv("DEV"))
|
|
||||||
}
|
|
||||||
|
|
||||||
http.Handle("/", http.RedirectHandler("/s/", http.StatusMovedPermanently))
|
|
||||||
http.Handle("/s/", http.StripPrefix("/s/", http.FileServer(fs)))
|
|
||||||
|
|
||||||
if err := http.ListenAndServe(*addr, nil); err != nil {
|
if err := http.ListenAndServe(*addr, nil); err != nil {
|
||||||
log.Fatal("ListenAndServe:", err)
|
log.Fatal("ListenAndServe:", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<!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>
|
||||||
Reference in New Issue
Block a user