1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-11 18:32:50 +00:00

got angular routing working - starting on html components

This commit is contained in:
2016-05-15 01:58:38 -05:00
parent d680c85c4a
commit 73fcbe6a5f
22 changed files with 778 additions and 42 deletions

View File

@@ -1,24 +1,42 @@
package route
import (
//"encoding/json"
//"fmt"
"github.com/julienschmidt/httprouter"
"net/http"
"github.com/mgerb42/mywebsite/controller"
"github.com/mgerb42/mywebsite/controller/api"
)
func Routes() *httprouter.Router {
r := httprouter.New()
r.GET("/", controller.IndexGet)
r.GET("/api/:fname/:lname", api.TestApiCall)
//set up public folder path
r.ServeFiles("/public/*filepath", http.Dir("./public"))
//404 not found
r.NotFound = http.NotFoundHandler()
//route every invalid request to template file
//routing is all handled on the client side with angular
r.NotFound = http.HandlerFunc(fileHandler("./public/view/template.html"))
return r
}
//route requests to static files
func routerFileHandler(path string) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
http.ServeFile(w, r, path)
}
}
//function to serve files with standard net/http library
func fileHandler(path string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, path)
}
}