-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
34 lines (29 loc) · 833 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
import (
"net/http"
"fmt"
"github.com/gorilla/mux"
"io/ioutil"
)
// The new router function creates the router and
func newRouter() *mux.Router {
r := mux.NewRouter()
r.HandleFunc("/", ClientHandler)
r.HandleFunc("/ws", WebsocketHandler)
return r
}
func ClientHandler(w http.ResponseWriter, r *http.Request) {
// If it does then we need to return the contents of it's file sin a javascript array, injected into the index.html page.
bytes, err := ioutil.ReadFile("template.html")
if err != nil {
fmt.Println("Could not open templates.html :: ", err)
}
var templatebody = string(bytes)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, templatebody)
}
func main() {
r := newRouter()
fmt.Println("Tune server started on: 3434")
http.ListenAndServe(":3434", r)
}