kataras / neffos

A modern, fast and scalable websocket framework with elegant API written in Go
http://bit.ly/neffos-wiki
MIT License
572 stars 47 forks source link

[BUG] how to recover program #78

Open Karrrrrrrr opened 1 year ago

Karrrrrrrr commented 1 year ago

if I have some runtime error in hooks(OnConnect function or any other), this program will abort so how to save program not abort

package main

import (
    "github.com/gin-gonic/gin"
    "github.com/gorilla/websocket"
    "github.com/kataras/neffos"
    "github.com/kataras/neffos/gorilla"
    "net/http"
)

const (
    namespace = "default"
    timeout   = 0 // 30 * time.Second
)

var handler = neffos.WithTimeout{
    ReadTimeout:  timeout,
    WriteTimeout: timeout,
    Namespaces: neffos.Namespaces{
        namespace: neffos.Events{},
    },
}

func main() {
    upgrader := gorilla.Upgrader(websocket.Upgrader{CheckOrigin: func(r *http.Request) bool {
        return true
    }})
    server(upgrader)
}

func server(upgrader neffos.Upgrader) {
    srv := neffos.New(upgrader, handler)

    srv.OnConnect = func(c *neffos.Conn) error {
        var i *int
        *i = 1
        // this process will abort at this
        // so how to continue and recover process
        return nil
    }

    app := gin.New()

    app.GET("/echo", gin.WrapH(srv))

    app.Run()

}