| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 | package modelimport (	"net/url"	"strings")type Environment struct {	Model	Name          string `json:"name"`	URL           string `json:"url"`	Token         string `json:"token"`	OperationSync bool   `json:"operation_sync"`	SyncApiRegex  string `json:"sync_api_regex"`}func (e *Environment) GetWebSocketURL(uri string) (decodedUri string, err error) {	baseUrl, err := url.Parse(e.URL)	if err != nil {		return	}	defaultPort := ""	if baseUrl.Port() == "" {		switch baseUrl.Scheme {		default:			fallthrough		case "http":			defaultPort = "80"		case "https":			defaultPort = "443"		}		baseUrl.Host = baseUrl.Hostname() + ":" + defaultPort	}	u, err := url.JoinPath(baseUrl.String(), uri)	if err != nil {		return	}	decodedUri, err = url.QueryUnescape(u)	if err != nil {		return	}	// http will be replaced with ws, https will be replaced with wss	decodedUri = strings.ReplaceAll(decodedUri, "http", "ws")	return}
 |