func NewGateway(settings Settings) *Gateway {
	gw := Gateway{
		settings: settings,
	}
	gw.setErrorHandler(settings.ErrorHandler)
	gw.setConnectHandler(settings.ConnectHandler)
	return &gw
}
NewGateway instanciates a Gateway
package gw
import (
	"bytes"
	"crypto/tls"
	"fmt"
	"io"
	"net"
	"net/http"
	"github.com/gorilla/websocket"
)
type ErrorHandler func(error)
type ConnectHandler func(*NatsConn, *http.Request, *websocket.Conn) error
type NatsServerInfo string
type Settings struct {
	NatsAddr       string
	EnableTLS      bool
	TLSConfig      *tls.Config
	ConnectHandler ConnectHandler
	ErrorHandler   ErrorHandler
	WSUpgrader     *websocket.Upgrader
	Trace          bool
}
type Gateway struct {
	settings      Settings
	onError       ErrorHandler
	handleConnect ConnectHandler
}
var defaultUpgrader = websocket.Upgrader{
	ReadBufferSize:  1024,
	WriteBufferSize: 1024,
}
type NatsConn struct {
	Conn       net.Conn
	CmdReader  CommandsReader
	ServerInfo NatsServerInfo
}
func (gw *Gateway) defaultConnectHandler(natsConn *NatsConn, r *http.Request, wsConn *websocket.Conn) error {
	infoCmd := append([]byte("INFO "), []byte(natsConn.ServerInfo)...)
	infoCmd = append(infoCmd, byte('\r'), byte('\n'))
	if gw.settings.Trace {
		fmt.Println("[TRACE] <--", string(infoCmd))
	}
	if err := wsConn.WriteMessage(websocket.TextMessage, infoCmd); err != nil {
		return err
	}
	return nil
}
func defaultErrorHandler(err error) {
	fmt.Println("[ERROR]", err)
}
func copyAndTrace(prefix string, dst io.Writer, src io.Reader, buf []byte) (int64, error) {
	read, err := src.Read(buf)
	if err != nil {
		return 0, err
	}
	fmt.Println("[TRACE]", prefix, string(buf[:read]))
	written, err := dst.Write(buf[:read])
	if written != read {
		return int64(written), io.ErrShortWrite
	}
	return int64(written), err
}