1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
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 (
Server = institute.Server
Servers = institute.Servers
)
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: u,
DisplayName: map[string]string{"en": pu.Hostname()},
Type: server.TypeCustom,
}
if err := api.Endpoints(ctx, &b); err != nil {
return nil, err
}
API := b.Endpoints.API.V3
s := &Server{Basic: b}
s.Auth.Init(u, API.Authorization, API.Token)
return s, nil
}
|