func (connectionSettings *ConnectionSettings) GetConnectFunc(state *session.State, appGUID, externalhost string, customHeaders http.Header) (func() (string, error), error) {
	header, err := connectionSettings.GetHeaders(state, externalhost)
	if err != nil {
		return nil, errors.WithStack(err)
	}
	switch connectionSettings.Mode {
	case JWT:
		return connectionSettings.JwtSettings.GetConnectFunc(state, connectionSettings, appGUID, externalhost, header, customHeaders), nil
	case WS:
		return connectionSettings.WsSettings.GetConnectFunc(state, connectionSettings, appGUID, externalhost, header, customHeaders), nil
	default:
		return nil, errors.Errorf("Unknown connection mode <%d>", connectionSettings.Mode)
	}
}
GetConnectFunc Get function for connecting to sense
package connection
import (
	"fmt"
	"net/http"
	"net/url"
	"strconv"
	"strings"
	"sync"
	"text/template"
	"time"
	jsoniter "github.com/json-iterator/go"
	"github.com/pkg/errors"
	"github.com/qlik-oss/gopherciser/enummap"
	"github.com/qlik-oss/gopherciser/helpers"
	"github.com/qlik-oss/gopherciser/session"
	"github.com/qlik-oss/gopherciser/users"
)
type (
	AuthenticationMode int
	ConnectionSettings struct {
		Mode AuthenticationMode `json:"mode" doc-key:"config.connectionSettings.mode"`
		JwtSettings *ConnectJWTSettings `json:"jwtsettings,omitempty" doc-key:"config.connectionSettings.jwtsettings"`
		WsSettings *ConnectWsSettings `json:"wssettings,omitempty" doc-key:"config.connectionSettings.wssettings"`
		Server string `json:"server" doc-key:"config.connectionSettings.server"`
		VirtualProxy string `json:"virtualproxy" doc-key:"config.connectionSettings.virtualproxy"`
		RawURL string `json:"rawurl,omitempty" doc-key:"config.connectionSettings.rawurl"`
		Port int `json:"port,omitempty" doc-key:"config.connectionSettings.port"`
		Security bool `json:"security" doc-key:"config.connectionSettings.security"`
		Allowuntrusted bool `json:"allowuntrusted" doc-key:"config.connectionSettings.allowuntrusted"`
		AppExt *string `json:"appext,omitempty" doc-key:"config.connectionSettings.appext"`
		Headers map[string]string `json:"headers" doc-key:"config.connectionSettings.headers"`
		syncTemplates sync.Once
		templates     map[string]*template.Template
	}
)
const (
	JWT AuthenticationMode = iota
	WS
)
var (
	funcMap = template.FuncMap{
		"now": time.Now,
	}
	jsonit = jsoniter.ConfigCompatibleWithStandardLibrary
)
func (value AuthenticationMode) GetEnumMap() *enummap.EnumMap {
	enumMap, _ := enummap.NewEnumMap(map[string]int{
		"jwt": int(JWT),
		"ws":  int(WS),
	})
	return enumMap
}
func (value *AuthenticationMode) UnmarshalJSON(arg []byte) error {
	i, err := value.GetEnumMap().UnMarshal(arg)
	if err != nil {
		return errors.Wrap(err, "Failed to unmarshal AuthenticationMode")
	}
	*value = AuthenticationMode(i)
	return nil
}
func (value AuthenticationMode) MarshalJSON() ([]byte, error) {
	str, err := value.GetEnumMap().String(int(value))
	if err != nil {
		return nil, errors.Errorf("Unknown AuthenticationMode<%d>", value)
	}
	return []byte(fmt.Sprintf(`"%s"`, str)), nil
}
func (connectionSettings *ConnectionSettings) Validate() error {
	switch connectionSettings.Mode {
	case JWT:
		if err := connectionSettings.JwtSettings.Validate(); err != nil {
			return errors.WithStack(err)
		}
	case WS:
		if err := connectionSettings.WsSettings.Validate(); err != nil {
			return errors.WithStack(err)
		}
	default:
		return errors.Errorf("Unknown connection mode <%d>", connectionSettings.Mode)
	}
	if connectionSettings.RawURL != "" {
		if strings.HasPrefix(connectionSettings.RawURL, "wss://") ||
			strings.HasPrefix(connectionSettings.RawURL, "ws://") {
			return nil
		}
		return errors.Errorf("Invalid raw url<%s>, must have protocol wss:// or ws://", connectionSettings.RawURL)
	}
	return nil
}