picatz / httpz

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

httpz

Collection of packages that extend net/http functionality.

Package Description
websocket Implements the WebSocket protocol (RFC6455).
ratelimit Rate limiting middleware.
secureheaders Common security HTTP response header middleware.

Websocket

hf := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    conn, _ := websocket.Upgrade(w, r, nil)
    defer conn.Close()

    for {
        frame, _ := conn.ReadFrame()

        switch frame.Type() {
        case websocket.TextFrame:
            slog.Info("recvd text frame", "payload" frame.Payload())
        case websocket.CloseFrame:
            return
        default:
            // handle other types
        }
    }
})

About

License:Mozilla Public License 2.0


Languages

Language:Go 100.0%