Compare commits
3 Commits
master
...
embed-asse
Author | SHA1 | Date | |
---|---|---|---|
b7bd99e465 | |||
5f4b24ba35 | |||
96e4a101d8 |
4
flags.go
4
flags.go
@ -5,6 +5,4 @@ import (
|
||||
)
|
||||
|
||||
var addr = flag.String("addr", ":8000", "http service address")
|
||||
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")
|
||||
var dbFile = flag.String("db", "db.json", "output database")
|
||||
|
6
gen.go
Normal file
6
gen.go
Normal file
@ -0,0 +1,6 @@
|
||||
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/...
|
17
handlers.go
17
handlers.go
@ -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")
|
||||
@ -33,7 +18,7 @@ func passHandler(resp http.ResponseWriter, req *http.Request) {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = ioutil.WriteFile(*db_file, b, 0644)
|
||||
err = ioutil.WriteFile(*dbFile, b, 0644)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
27
license
27
license
@ -1,27 +0,0 @@
|
||||
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.
|
40
main.go
40
main.go
@ -7,8 +7,10 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/elazarl/go-bindata-assetfs"
|
||||
)
|
||||
|
||||
type Cred struct {
|
||||
@ -20,8 +22,8 @@ var creds = make([]Cred, 0)
|
||||
var m = sync.Mutex{}
|
||||
var templates *template.Template
|
||||
|
||||
func init_db() {
|
||||
b, err := ioutil.ReadFile(*db_file)
|
||||
func initDb() {
|
||||
b, err := ioutil.ReadFile(*dbFile)
|
||||
if err != nil {
|
||||
log.Println("Problem opening db file ... ignoring ...", err)
|
||||
}
|
||||
@ -34,21 +36,27 @@ 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)
|
||||
initDb()
|
||||
|
||||
http.HandleFunc("/pass", passHandler)
|
||||
http.HandleFunc("/api/1.0/creds/", credHandler)
|
||||
http.Handle("/s/", http.StripPrefix("/s/",
|
||||
http.FileServer(http.Dir(*static_files))))
|
||||
|
||||
var fs http.FileSystem
|
||||
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 {
|
||||
log.Fatal("ListenAndServe:", err)
|
||||
}
|
||||
|
@ -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>
|
Loading…
Reference in New Issue
Block a user