telebit/listener_admin.go
Henry Camacho 894bd997a9 Restructured code, using module use, created logging package as a helper
- altered code to support a client bound interface
- altered code to support an admin bound interface
- added configurations and defaults.
- removed timeout function at the end of main.
- the final go routine was converted to a foreground routine.
2017-02-05 21:19:04 -06:00

37 lines
965 B
Go

package main
import (
"html/template"
"net/http"
)
//launchAdminListener - starts up http listeners and handles various URI paths
func launchAdminListener() {
loginfo.Println("starting Admin Listener")
http.HandleFunc("/admin", handlerServeAdminContent)
err := http.ListenAndServeTLS(*argServerAdminBinding, "certs/fullchain.pem", "certs/privkey.pem", nil)
if err != nil {
logfatal.Println("ListenAndServe: ", err)
panic(err)
}
}
func handlerServeAdminContent(w http.ResponseWriter, r *http.Request) {
switch url := r.URL.Path; url {
case "/":
handleConnectionWebSocket(connectionTable, w, r, false)
//w.Header().Set("Content-Type", "text/html; charset=utf-8")
//template.Must(template.ParseFiles("html/client.html")).Execute(w, r.Host)
case "/admin":
w.Header().Set("Content-Type", "text/html; charset=utf-8")
template.Must(template.ParseFiles("html/admin.html")).Execute(w, r.Host)
default:
http.Error(w, "Not Found", 404)
}
}