purged websocket garbage, just going to use web grpc
parent
f8c51d27a9
commit
9086b80994
@ -1,4 +0,0 @@
|
||||
INFLUXDB_USERNAME=admin
|
||||
INFLUXDB_PASSWORD=forelight
|
||||
INFLUXDB_ORG=ForeLight
|
||||
INFLUXDB_BUCKET=test
|
@ -1 +1 @@
|
||||
fe0b33dbcc236558952eb8f9f91422c9
|
||||
0bbb9b59233e7c3a6b58764d03788b82
|
||||
|
@ -1,89 +0,0 @@
|
||||
package websocket
|
||||
|
||||
// creates websocket server and upgrades incoming connections
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
ws "github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
type ReactorTest struct {
|
||||
Id int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type WebSocket struct {
|
||||
// dummy struct for interface
|
||||
N string
|
||||
}
|
||||
|
||||
func New() *WebSocket {
|
||||
return &WebSocket{}
|
||||
}
|
||||
|
||||
func (s *WebSocket) Start() {
|
||||
fmt.Println("Starting ws server!")
|
||||
setupRoutes()
|
||||
http.ListenAndServe(":8080", nil)
|
||||
}
|
||||
|
||||
// default opts allow all origins
|
||||
var upgrader = ws.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool { return true },
|
||||
}
|
||||
|
||||
// reader
|
||||
func reader(conn *ws.Conn) {
|
||||
|
||||
for {
|
||||
// read forever
|
||||
//messageType, p, err := conn.ReadMessage()
|
||||
_, p, err := conn.ReadMessage()
|
||||
|
||||
if err != nil {
|
||||
if ws.IsCloseError(err, ws.CloseNormalClosure, ws.CloseGoingAway) {
|
||||
// normally closed
|
||||
return
|
||||
}
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("Msg: %s\n", string(p))
|
||||
}
|
||||
}
|
||||
|
||||
func serverWs(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println(r.Host)
|
||||
|
||||
websocket, err := upgrader.Upgrade(w, r, nil)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// try sending reactor
|
||||
t1 := &ReactorTest{Id: 1111, Name: "test1"}
|
||||
t2 := &ReactorTest{Id: 1112, Name: "test2"}
|
||||
t3 := &ReactorTest{Id: 1113, Name: "test3"}
|
||||
n := []*ReactorTest{t1, t2, t3}
|
||||
msg, err := json.Marshal(n)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// pass to connection
|
||||
if err := websocket.WriteMessage(ws.TextMessage, msg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// pass to reader
|
||||
reader(websocket)
|
||||
}
|
||||
|
||||
func setupRoutes() {
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "Simple Server")
|
||||
})
|
||||
|
||||
http.HandleFunc("/ws", serverWs)
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
// implemenets a reactor object with websocket methods
|
||||
package websocket
|
Loading…
Reference in New Issue