From 9086b8099484cecf6a557895336fd572cf5d4c16 Mon Sep 17 00:00:00 2001 From: KeeganForelight Date: Fri, 16 Jun 2023 15:44:37 -0400 Subject: [PATCH] purged websocket garbage, just going to use web grpc --- .env | 4 -- .task/checksum/go-build | 2 +- cmd/server/main.go | 13 ----- internal/pkg/websocket/connect.go | 89 ------------------------------- internal/pkg/websocket/reactor.go | 2 - 5 files changed, 1 insertion(+), 109 deletions(-) delete mode 100644 .env delete mode 100644 internal/pkg/websocket/connect.go delete mode 100644 internal/pkg/websocket/reactor.go diff --git a/.env b/.env deleted file mode 100644 index ab2e438..0000000 --- a/.env +++ /dev/null @@ -1,4 +0,0 @@ -INFLUXDB_USERNAME=admin -INFLUXDB_PASSWORD=forelight -INFLUXDB_ORG=ForeLight -INFLUXDB_BUCKET=test diff --git a/.task/checksum/go-build b/.task/checksum/go-build index 464558c..aed43fb 100644 --- a/.task/checksum/go-build +++ b/.task/checksum/go-build @@ -1 +1 @@ -fe0b33dbcc236558952eb8f9f91422c9 +0bbb9b59233e7c3a6b58764d03788b82 diff --git a/cmd/server/main.go b/cmd/server/main.go index 42f6bf5..1c217ca 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -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 diff --git a/internal/pkg/websocket/connect.go b/internal/pkg/websocket/connect.go deleted file mode 100644 index 4378083..0000000 --- a/internal/pkg/websocket/connect.go +++ /dev/null @@ -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) -} diff --git a/internal/pkg/websocket/reactor.go b/internal/pkg/websocket/reactor.go deleted file mode 100644 index d055e26..0000000 --- a/internal/pkg/websocket/reactor.go +++ /dev/null @@ -1,2 +0,0 @@ -// implemenets a reactor object with websocket methods -package websocket