|
@@ -148,14 +148,16 @@ var ( |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
var paths = map[string]string { |
|
|
var paths = map[string]string { |
|
|
"home": "home.tpl", |
|
|
|
|
|
"terms": "terms.tpl", |
|
|
|
|
|
"app": "app.tpl", |
|
|
|
|
|
|
|
|
"home": "views/home.tpl", |
|
|
|
|
|
"terms": "views/terms.tpl", |
|
|
|
|
|
"app": "views/app.tpl", |
|
|
|
|
|
"test": "views/test.tpl", |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var pages = map[string]Page { |
|
|
var pages = map[string]Page { |
|
|
"home": cache("home", "Home"), |
|
|
"home": cache("home", "Home"), |
|
|
"terms": cache("terms", "Terms and Conditions"), |
|
|
"terms": cache("terms", "Terms and Conditions"), |
|
|
|
|
|
"test": cache("test", "PDF test"), |
|
|
"app": cache("app", "App"), |
|
|
"app": cache("app", "App"), |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -176,7 +178,7 @@ func (c UserClaims) Valid() error { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func cache(name string, title string) Page { |
|
|
func cache(name string, title string) Page { |
|
|
var p = []string{"master.tpl", paths[name]} |
|
|
|
|
|
|
|
|
var p = []string{"views/master.tpl", paths[name]} |
|
|
tpl := template.Must(template.ParseFiles(p...)) |
|
|
tpl := template.Must(template.ParseFiles(p...)) |
|
|
return Page{tpl: tpl, |
|
|
return Page{tpl: tpl, |
|
|
Title: title, |
|
|
Title: title, |
|
@@ -1512,6 +1514,47 @@ func validateEstimate(w http.ResponseWriter, db *sql.DB, r *http.Request) { |
|
|
if err != nil { http.Error(w, err.Error(), 406); return } |
|
|
if err != nil { http.Error(w, err.Error(), 406); return } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func showPDF(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
|
// var args []string |
|
|
|
|
|
|
|
|
|
|
|
// p := r.URL.Path |
|
|
|
|
|
db, err := sql.Open("mysql", |
|
|
|
|
|
fmt.Sprintf("%s:%s@tcp(127.0.0.1:3306)/skouter", |
|
|
|
|
|
config["DBUser"], |
|
|
|
|
|
config["DBPass"])) |
|
|
|
|
|
|
|
|
|
|
|
// w.Header().Set("Content-Type", "application/json; charset=UTF-8") |
|
|
|
|
|
err = db.Ping() |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
fmt.Println("Bad database configuration: %v\n", err) |
|
|
|
|
|
panic(err) |
|
|
|
|
|
// maybe os.Exit(1) instead |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var pa = template.Must(template.ParseFiles("views/master.tpl", |
|
|
|
|
|
"views/test.tpl")) |
|
|
|
|
|
|
|
|
|
|
|
// claims, err := getClaims(r) |
|
|
|
|
|
if err != nil { w.WriteHeader(500); return } |
|
|
|
|
|
users, err := queryUsers(db, 1) |
|
|
|
|
|
|
|
|
|
|
|
info := struct { |
|
|
|
|
|
Title string |
|
|
|
|
|
Name string |
|
|
|
|
|
User User |
|
|
|
|
|
}{ |
|
|
|
|
|
Title: "test PDF", |
|
|
|
|
|
Name: "idk-random-name", |
|
|
|
|
|
User: users[0], |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// fmt.Println(info) |
|
|
|
|
|
|
|
|
|
|
|
err = pa.Execute(w, info) |
|
|
|
|
|
if err != nil {fmt.Println(err)} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func api(w http.ResponseWriter, r *http.Request) { |
|
|
func api(w http.ResponseWriter, r *http.Request) { |
|
|
var args []string |
|
|
var args []string |
|
|
|
|
|
|
|
@@ -1595,9 +1638,9 @@ func api(w http.ResponseWriter, r *http.Request) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func route(w http.ResponseWriter, r *http.Request) { |
|
|
func route(w http.ResponseWriter, r *http.Request) { |
|
|
var page Page |
|
|
|
|
|
|
|
|
var page Page |
|
|
var args []string |
|
|
var args []string |
|
|
p := r.URL.Path |
|
|
|
|
|
|
|
|
p := r.URL.Path |
|
|
|
|
|
|
|
|
switch { |
|
|
switch { |
|
|
case r.Method == "GET" && match(p, "/", &args): |
|
|
case r.Method == "GET" && match(p, "/", &args): |
|
@@ -1606,6 +1649,9 @@ func route(w http.ResponseWriter, r *http.Request) { |
|
|
page = pages[ "terms" ] |
|
|
page = pages[ "terms" ] |
|
|
case match(p, "/app", &args): |
|
|
case match(p, "/app", &args): |
|
|
page = pages[ "app" ] |
|
|
page = pages[ "app" ] |
|
|
|
|
|
case match(p, "/test", &args): |
|
|
|
|
|
showPDF(w, r) |
|
|
|
|
|
return |
|
|
default: |
|
|
default: |
|
|
http.NotFound(w, r) |
|
|
http.NotFound(w, r) |
|
|
return |
|
|
return |
|
|