App, server helpers
This commit is contained in:
parent
13f971a731
commit
3f034017f2
|
@ -0,0 +1,20 @@
|
||||||
|
{{define "app"}}
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf8">
|
||||||
|
<title>Empact</title>
|
||||||
|
<link rel="stylesheet" href="/app/hello.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>Please Sign in with your GitHub account</h1>
|
||||||
|
<a href="/auth/signin">
|
||||||
|
<img src="/app/github_mark_120.png">
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<script src="/app/hello.js"></script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
{{end}}
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
|
@ -1,6 +1,7 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -10,13 +11,16 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
helloTmpl = template.New("hello")
|
helloTmpl = template.New("hello")
|
||||||
|
appTmpl = template.New("app")
|
||||||
|
box = rice.MustFindBox("app")
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
box := rice.MustFindBox("static")
|
parseTemplate("hello.tmpl", helloTmpl)
|
||||||
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(box.HTTPBox())))
|
parseTemplate("app.tmpl", appTmpl)
|
||||||
tmplText, _ := box.String("hello.tmpl")
|
|
||||||
helloTmpl, _ = helloTmpl.Parse(tmplText)
|
// Serving static files
|
||||||
|
http.Handle("/app/", http.StripPrefix("/app/", http.FileServer(box.HTTPBox())))
|
||||||
|
|
||||||
http.HandleFunc("/", sessionHandler)
|
http.HandleFunc("/", sessionHandler)
|
||||||
http.HandleFunc("/api/", authHandler)
|
http.HandleFunc("/api/", authHandler)
|
||||||
|
@ -32,3 +36,21 @@ func Start() {
|
||||||
fmt.Println("Starting server at http://localhost:8080")
|
fmt.Println("Starting server at http://localhost:8080")
|
||||||
http.ListenAndServe(":8080", nil)
|
http.ListenAndServe(":8080", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseTemplate(file string, tmpl *template.Template) {
|
||||||
|
if tmplText, err := box.String(file); err == nil {
|
||||||
|
tmpl, _ = tmpl.Parse(tmplText)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func respondWith(w http.ResponseWriter, resp interface{}) {
|
||||||
|
b, err := json.Marshal(resp)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json; charset=utf8")
|
||||||
|
w.Write(b)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue