|
@@ -9,7 +9,6 @@ package web
|
|
|
|
|
|
import (
|
|
import (
|
|
"errors"
|
|
"errors"
|
|
- "github.com/gorilla/mux"
|
|
|
|
"html/template"
|
|
"html/template"
|
|
"log"
|
|
"log"
|
|
"net/http"
|
|
"net/http"
|
|
@@ -17,6 +16,9 @@ import (
|
|
"path"
|
|
"path"
|
|
"path/filepath"
|
|
"path/filepath"
|
|
"strconv"
|
|
"strconv"
|
|
|
|
+
|
|
|
|
+ "github.com/gorilla/mux"
|
|
|
|
+ "github.com/gorilla/sessions"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -28,6 +30,8 @@ const (
|
|
|
|
|
|
|
|
|
|
const (
|
|
const (
|
|
|
|
+ HtmlFormType = "application/x-www-form-urlencoded"
|
|
|
|
+
|
|
|
|
|
|
HtmlType = "text/html"
|
|
HtmlType = "text/html"
|
|
|
|
|
|
@@ -39,12 +43,15 @@ type Globals struct {
|
|
AssetsBaseURL string
|
|
AssetsBaseURL string
|
|
AssetsVersion int
|
|
AssetsVersion int
|
|
AssetsPath string
|
|
AssetsPath string
|
|
|
|
+ SessionKey []byte
|
|
|
|
+ SessionName string
|
|
SiteBaseURL string
|
|
SiteBaseURL string
|
|
RefreshDelay int
|
|
RefreshDelay int
|
|
SiteName string
|
|
SiteName string
|
|
}
|
|
}
|
|
|
|
|
|
var globals Globals
|
|
var globals Globals
|
|
|
|
+var store *sessions.CookieStore
|
|
var tmpl *template.Template
|
|
var tmpl *template.Template
|
|
|
|
|
|
|
|
|
|
@@ -75,9 +82,11 @@ func setupControllerRoutes(router *mux.Router) {
|
|
}).
|
|
}).
|
|
Methods("GET", "HEAD").
|
|
Methods("GET", "HEAD").
|
|
Name(RouteGetShort)
|
|
Name(RouteGetShort)
|
|
- router.HandleFunc("/", handlePostTarget).
|
|
+ router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
+ handlePostTarget(w, r, router)
|
|
|
|
+ }).
|
|
HeadersRegexp("Accept", HtmlTypeRegex).
|
|
HeadersRegexp("Accept", HtmlTypeRegex).
|
|
- Headers("Content-Type", HtmlType).
|
|
+ Headers("Content-Type", HtmlFormType).
|
|
Methods("POST").
|
|
Methods("POST").
|
|
Name(RoutePostTarget)
|
|
Name(RoutePostTarget)
|
|
router.HandleFunc("/", handleGetRoot).
|
|
router.HandleFunc("/", handleGetRoot).
|
|
@@ -96,8 +105,10 @@ func setupTemplates(configAssetsPath string) {
|
|
ParseFiles(
|
|
ParseFiles(
|
|
base+"/201.gohtml",
|
|
base+"/201.gohtml",
|
|
base+"/404.gohtml",
|
|
base+"/404.gohtml",
|
|
|
|
+ base+"/409.gohtml",
|
|
base+"/home.gohtml",
|
|
base+"/home.gohtml",
|
|
layout+"/analytics.gohtml",
|
|
layout+"/analytics.gohtml",
|
|
|
|
+ layout+"/flashes.gohtml",
|
|
layout+"/footer.gohtml",
|
|
layout+"/footer.gohtml",
|
|
layout+"/inlinecss.gohtml",
|
|
layout+"/inlinecss.gohtml",
|
|
))
|
|
))
|
|
@@ -110,9 +121,13 @@ func SetupGlobals(c map[string]interface{}) {
|
|
AssetsPath: c["assetspath"].(string),
|
|
AssetsPath: c["assetspath"].(string),
|
|
AssetsVersion: c["assetsversion"].(int),
|
|
AssetsVersion: c["assetsversion"].(int),
|
|
RefreshDelay: c["refreshdelay"].(int),
|
|
RefreshDelay: c["refreshdelay"].(int),
|
|
|
|
+ SessionKey: []byte(c["sessionkey"].(string)),
|
|
|
|
+ SessionName: c["sessionname"].(string),
|
|
SiteBaseURL: c["sitebaseurl"].(string),
|
|
SiteBaseURL: c["sitebaseurl"].(string),
|
|
SiteName: c["sitename"].(string),
|
|
SiteName: c["sitename"].(string),
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ store = sessions.NewCookieStore(globals.SessionKey)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -123,10 +138,10 @@ To build URLs for assets, use URLForAsset().
|
|
- ns: the assets namespace. One of "js", "css', "images".
|
|
- ns: the assets namespace. One of "js", "css', "images".
|
|
- path: the asset path relative to the project root
|
|
- path: the asset path relative to the project root
|
|
*/
|
|
*/
|
|
-func URLFromRoute(router mux.Router, name string, params map[string]string) string {
|
|
+func URLFromRoute(router *mux.Router, name string, params map[string]string) string {
|
|
- log.Println(name, params)
|
|
+ log.Println("Generating route:", name, params)
|
|
|
|
|
|
- return name
|
|
+ return "/"
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|