purged websocket garbage, just going to use web grpc

main
KeeganForelight 1 year ago
parent f8c51d27a9
commit 9086b80994

@ -1,4 +0,0 @@
INFLUXDB_USERNAME=admin
INFLUXDB_PASSWORD=forelight
INFLUXDB_ORG=ForeLight
INFLUXDB_BUCKET=test

@ -1 +1 @@
fe0b33dbcc236558952eb8f9f91422c9
0bbb9b59233e7c3a6b58764d03788b82

@ -8,7 +8,6 @@ import (
"FRMS/internal/pkg/config"
"FRMS/internal/pkg/logging"
"FRMS/internal/pkg/server"
"FRMS/internal/pkg/websocket"
"os"
"github.com/spf13/viper"
@ -26,14 +25,6 @@ func NewConfig(fname string) *viper.Viper {
return config.LoadConfig(fname)
}
type ws interface {
Start()
}
func NewWebSocket() ws {
return websocket.New()
}
func main() {
// lets get this bread
gracefulShutdown := make(chan os.Signal, 1)
@ -47,10 +38,6 @@ func main() {
c := NewCoordinator(conf, errCh)
go c.Start()
logging.Debug(logging.DStart, "CCO 01 Server %s started", conf.Get("name"))
// starting websocket server
w := NewWebSocket()
go w.Start()
select {
case err := <-errCh: // blocking to wait for any errors and keep alive otherwise

@ -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…
Cancel
Save