nginx-ui/server/model/environment.go
superlollipop 6ede443bbe
针对nginx+keeplived的vip映射管理方案 (#154)
* fixed environment indicator display overlay & edit not obtain newest data

* finished environment operation sync

* fix: environment indicator display overflow not ellipsis

---------

Co-authored-by: 0xJacky <me@jackyu.cn>
2023-08-21 21:56:07 +08:00

53 lines
957 B
Go

package model
import (
"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
}