diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-04-26 12:13:09 +0200 |
|---|---|---|
| committer | Jeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com> | 2023-09-25 09:43:37 +0200 |
| commit | 188d64d6cf018e410b02714d3125de15aa8ce928 (patch) | |
| tree | cc0f9648c1ced7a2b725cd2c6e53f34beeee5cff /internal | |
| parent | b493dc14c32c889f68410385bed7251ef36ad1a4 (diff) | |
Custom: Use the hostname for custom servers display name
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/server/custom/custom.go | 14 |
1 files changed, 10 insertions, 4 deletions
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 } |
