diff --git a/client/server.go b/client/server.go index 8aa46dc..1a1f1eb 100644 --- a/client/server.go +++ b/client/server.go @@ -53,6 +53,21 @@ func CreateServerFromUid(uid string) *Server { return &is } +// CreateServerFromMeowUrl creates a server from a meow url, ex : meow://mylogin:mypassword@https://my.meowserver.example:8443/meow/ +func CreateServerFromMeowUrl(meowurl string) *Server { + uid := strings.Split(meowurl, "://")[1] + return CreateServerFromUid(uid) +} + +// CreateServerFromInvitationLink creates a server from a meow url, ex : meow://mylogin:mypassword@https://my.meowserver.example:8443/meow/invitationCode +func CreateServerFromInvitationLink(meowurl string) *Server { + // remove the invitation code, last token after a / + meowurlTable := strings.Split(meowurl, "/") + // join all elements with / except the last one + uid := strings.Join(meowurlTable[:len(meowurlTable)-1], "/") + return CreateServerFromUid(uid) +} + // GetServerCard returns a server card from a server func (ints *Server) GetServerCard() *meowlib.ServerCard { var sc meowlib.ServerCard @@ -72,6 +87,13 @@ func (sc *Server) GetUid() string { return sc.Url } +func (sc *Server) GetMeowUrl() string { + if len(sc.Login) > 0 || len(sc.Password) > 0 { + return sc.Login + ":" + sc.Password + "@" + sc.Url + } + return "meow://" + sc.Url +} + // Create a server from a server card func CreateServerFromServerCard(server *meowlib.ServerCard) *Server { var is Server