|
@@ -1,4 +1,4 @@
|
|
|
-package main
|
|
|
+package pathway
|
|
|
|
|
|
import (
|
|
|
"io"
|
|
@@ -6,18 +6,19 @@ import (
|
|
|
"net/http"
|
|
|
"strings"
|
|
|
"sync"
|
|
|
+ // "nhooyr.io/websocket"
|
|
|
)
|
|
|
|
|
|
var (
|
|
|
- // variables to set during build-time
|
|
|
- debugging = ""
|
|
|
- version = "0.0-undefined"
|
|
|
- buildtime = "0000-00-00T00:00:00+0000"
|
|
|
-
|
|
|
// actual business end of the device
|
|
|
- paths = &sync.Map{}
|
|
|
+ paths *sync.Map
|
|
|
+ debugging string
|
|
|
)
|
|
|
|
|
|
+func init() {
|
|
|
+ paths = &sync.Map{}
|
|
|
+}
|
|
|
+
|
|
|
// Transfer holds a single tranferable connection to be read
|
|
|
type Transfer struct {
|
|
|
reader io.ReadCloser
|
|
@@ -57,7 +58,15 @@ func pathHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
if h := r.Header.Get("Connection"); len(h) > 0 && strings.ToLower(h) == "upgrade" {
|
|
|
if h = r.Header.Get("Upgrade"); len(h) > 0 && strings.ToLower(h) == "websocket" {
|
|
|
+ // c, err := websocket.Accept(w, r, nil)
|
|
|
+ // if err != nil {
|
|
|
+ // info("Websocket not accepted: %+s", err.Error())
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // defer c.Close(websocket.StatusInternalError, "the sky is falling")
|
|
|
info("Websocket connections not supported yet. Headers: %+v", r.Header)
|
|
|
+ // return
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -77,29 +86,6 @@ func pathHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func okHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
- w.WriteHeader(http.StatusOK)
|
|
|
- w.Write([]byte("ok"))
|
|
|
-}
|
|
|
-
|
|
|
-func emptyHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
- w.WriteHeader(http.StatusOK)
|
|
|
-}
|
|
|
-
|
|
|
-func main() {
|
|
|
- info("pathway version:%s buildtime:%s", version, buildtime)
|
|
|
-
|
|
|
- http.HandleFunc("/health", okHandler)
|
|
|
- http.HandleFunc("/favicon.ico", emptyHandler)
|
|
|
- http.HandleFunc("/robots.txt", emptyHandler)
|
|
|
- http.HandleFunc("/", pathHandler)
|
|
|
-
|
|
|
- err := http.ListenAndServe(":8080", nil)
|
|
|
- if err != nil {
|
|
|
- info("%s", err.Error())
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
func info(msg string, args ...interface{}) {
|
|
|
log.Printf("INFO | "+msg, args...)
|
|
|
}
|