mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-27 13:48:49 +08:00
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package api
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/go-zoo/bone"
|
|
"github.com/gorilla/websocket"
|
|
"github.com/mainflux/mainflux"
|
|
log "github.com/mainflux/mainflux/logger"
|
|
"github.com/mainflux/mainflux/ws"
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
)
|
|
|
|
const (
|
|
protocol = "ws"
|
|
readwriteBufferSize = 1024
|
|
)
|
|
|
|
var (
|
|
errUnauthorizedAccess = errors.New("missing or invalid credentials provided")
|
|
errMalformedSubtopic = errors.New("malformed subtopic")
|
|
)
|
|
|
|
var (
|
|
upgrader = websocket.Upgrader{
|
|
ReadBufferSize: readwriteBufferSize,
|
|
WriteBufferSize: readwriteBufferSize,
|
|
CheckOrigin: func(r *http.Request) bool { return true },
|
|
}
|
|
logger log.Logger
|
|
)
|
|
|
|
// MakeHandler returns http handler with handshake endpoint.
|
|
func MakeHandler(svc ws.Service, l log.Logger) http.Handler {
|
|
logger = l
|
|
|
|
mux := bone.New()
|
|
mux.GetFunc("/channels/:id/messages", handshake(svc))
|
|
mux.GetFunc("/channels/:id/messages/*", handshake(svc))
|
|
mux.GetFunc("/version", mainflux.Health(protocol))
|
|
mux.Handle("/metrics", promhttp.Handler())
|
|
|
|
return mux
|
|
}
|