From 188d64d6cf018e410b02714d3125de15aa8ce928 Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Wed, 26 Apr 2023 12:13:09 +0200 Subject: Custom: Use the hostname for custom servers display name --- internal/server/custom/custom.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'internal') diff --git a/internal/server/custom/custom.go b/internal/server/custom/custom.go index 14a72a5..d4a0508 100644 --- a/internal/server/custom/custom.go +++ b/internal/server/custom/custom.go @@ -2,11 +2,13 @@ package custom import ( "context" + "net/url" "github.com/eduvpn/eduvpn-common/internal/server/api" "github.com/eduvpn/eduvpn-common/internal/server/base" "github.com/eduvpn/eduvpn-common/internal/server/institute" "github.com/eduvpn/eduvpn-common/types/server" + "github.com/go-errors/errors" ) type ( @@ -14,10 +16,14 @@ type ( Servers = institute.Servers ) -func New(ctx context.Context, url string) (*Server, error) { +func New(ctx context.Context, u string) (*Server, error) { + pu, err := url.Parse(u) + if err != nil { + return nil, errors.WrapPrefix(err, "failed to parse custom server URL", 0) + } b := base.Base{ - URL: url, - DisplayName: map[string]string{"en": url}, + URL: u, + DisplayName: map[string]string{"en": pu.Hostname()}, Type: server.TypeCustom, } if err := api.Endpoints(ctx, &b); err != nil { @@ -26,6 +32,6 @@ func New(ctx context.Context, url string) (*Server, error) { API := b.Endpoints.API.V3 s := &Server{Basic: b} - s.Auth.Init(url, API.Authorization, API.Token) + s.Auth.Init(u, API.Authorization, API.Token) return s, nil } -- cgit v1.2.3