func NewHandlers(middlewareInstance Middleware, dataDir string) *Handlers {
	router := mux.NewRouter()
	handlers := &Handlers{
		middleware: middlewareInstance,
		Router:     router,
		upgrader:   websocket.Upgrader{},
		noiseConfig: noisemanager.NewNoiseConfig(
			dataDir, middlewareInstance.VerifyAppMiddlewarePairing),
		nClients:   0,
		clientsMap: make(map[int]chan<- []byte),
		eventQueue: make([]Event, 0),
	}
	handlers.Router.HandleFunc("/", handlers.rootHandler).Methods("GET")
	handlers.Router.HandleFunc("/version", handlers.versionHandler).Methods("GET")
	handlers.Router.HandleFunc("/ws", handlers.wsHandler)
	handlers.middlewareEvents = handlers.middleware.Start()
	go handlers.listenEvents()
	return handlers
}
NewHandlers returns a handler instance.
package handlers
import (
	"encoding/json"
	"log"
	"net/http"
	"sync"
	noisemanager "github.com/digitalbitbox/bitbox-base/middleware/src/noise"
	"github.com/digitalbitbox/bitbox-base/middleware/src/rpcmessages"
	"github.com/digitalbitbox/bitbox-base/middleware/src/rpcserver"
	"github.com/gorilla/mux"
	"github.com/gorilla/websocket"
)
type Middleware interface {
	Start() <-chan Event
	BackupHSMSecret() rpcmessages.ErrorResponse
	BackupSysconfig() rpcmessages.ErrorResponse
	EnableClearnetIBD(rpcmessages.ToggleSettingArgs) rpcmessages.ErrorResponse
	EnableRootLogin(rpcmessages.ToggleSettingArgs) rpcmessages.ErrorResponse
	EnableSSHPasswordLogin(rpcmessages.ToggleSettingArgs) rpcmessages.ErrorResponse
	EnableTor(rpcmessages.ToggleSettingArgs) rpcmessages.ErrorResponse
	EnableTorElectrs(rpcmessages.ToggleSettingArgs) rpcmessages.ErrorResponse
	EnableTorMiddleware(rpcmessages.ToggleSettingArgs) rpcmessages.ErrorResponse
	EnableTorSSH(rpcmessages.ToggleSettingArgs) rpcmessages.ErrorResponse
	FinalizeSetupWizard() rpcmessages.ErrorResponse
	GetBaseInfo() rpcmessages.GetBaseInfoResponse
	GetBaseUpdateProgress() rpcmessages.GetBaseUpdateProgressResponse
	GetServiceInfo() rpcmessages.GetServiceInfoResponse
	GetServiceStatus() rpcmessages.GetServiceStatusResponse
	IsBaseUpdateAvailable() rpcmessages.IsBaseUpdateAvailableResponse
	RebootBase() rpcmessages.ErrorResponse
	ReindexBitcoin() rpcmessages.ErrorResponse
	RestoreHSMSecret() rpcmessages.ErrorResponse
	RestoreSysconfig() rpcmessages.ErrorResponse
	ResyncBitcoin() rpcmessages.ErrorResponse
	SetHostname(rpcmessages.SetHostnameArgs) rpcmessages.ErrorResponse
	SetLoginPassword(rpcmessages.SetLoginPasswordArgs) rpcmessages.ErrorResponse
	SetupStatus() rpcmessages.SetupStatusResponse
	ShutdownBase() rpcmessages.ErrorResponse
	SystemEnv() rpcmessages.GetEnvResponse
	UpdateBase(rpcmessages.UpdateBaseArgs) rpcmessages.ErrorResponse
	UserAuthenticate(rpcmessages.UserAuthenticateArgs) rpcmessages.UserAuthenticateResponse
	UserChangePassword(rpcmessages.UserChangePasswordArgs) rpcmessages.ErrorResponse
	GetMiddlewareVersion() string
	ValidateToken(token string) error
	VerifyAppMiddlewarePairing(channelHash []byte) (bool, error)
}
type Handlers struct {
	Router *mux.Router
	upgrader         websocket.Upgrader
	middleware       Middleware
	middlewareEvents <-chan Event
	eventQueue       []Event
	noiseConfig *noisemanager.NoiseConfig
	nClients    int
	clientsMap  map[int]chan<- []byte
	mu          sync.Mutex
}
type Event struct {
	Identifier      []byte
	QueueIfNoClient bool
}