ing
This commit is contained in:
parent
7bf33cff21
commit
a99018b3d2
15
server.go
15
server.go
@ -1,7 +1,6 @@
|
||||
package overflow_gateway_websocket
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
@ -43,12 +42,11 @@ func NewServer(o *ServerOptions) Server {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *server) onPush(cb OnPushFunc) {
|
||||
|
||||
}
|
||||
|
||||
func (s *server) onError(ctx *fasthttp.RequestCtx, status int, reason error) {
|
||||
ctx.Response.Header.Set("Sec-Websocket-Version", "13")
|
||||
ctx.Error(http.StatusText(status), status)
|
||||
|
||||
s._option.OnError(ctx, status, reason)
|
||||
}
|
||||
|
||||
func (s *server) onDisconnected(c Client) {
|
||||
@ -61,16 +59,13 @@ func (s *server) onConnection(ctx *fasthttp.RequestCtx) {
|
||||
path := string(ctx.Path())
|
||||
co, ok := s._handlers[path]
|
||||
if !ok {
|
||||
ctx.Response.Header.Set("Sec-Websocket-Version", "13")
|
||||
ctx.Error(http.StatusText(fasthttp.StatusNotFound), fasthttp.StatusNotFound)
|
||||
|
||||
log.Printf("Path[%s] is not exist.", path)
|
||||
s.onError(ctx, fasthttp.StatusNotFound, nil)
|
||||
return
|
||||
}
|
||||
|
||||
s._upgrader.Upgrade(ctx, nil, func(conn *websocket.Conn, err error) {
|
||||
if err != nil {
|
||||
log.Print("upgrade:", err)
|
||||
s.onError(ctx, fasthttp.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
s._cMtx.Lock()
|
||||
|
@ -10,7 +10,6 @@ import (
|
||||
type (
|
||||
OnConnectionFunc func(c Client)
|
||||
OnDisconnectedFunc func(c Client)
|
||||
OnPushFunc func()
|
||||
)
|
||||
|
||||
const (
|
||||
|
Loading…
x
Reference in New Issue
Block a user