summaryrefslogtreecommitdiff
path: root/internal/server/custom.go
blob: 0d78308df01b7d3bcc9d04f4e7f6a3c27d34f769 (plain)
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
package server

import (
	"github.com/go-errors/errors"
)

func (ss *Servers) SetCustomServer(server Server) error {
	b, err := server.Base()
	if err != nil {
		return err
	}

	if b.Type != "custom_server" {
		return errors.WrapPrefix(err, "not a custom server", 0)
	}

	if _, ok := ss.CustomServers.Map[b.URL]; ok {
		ss.CustomServers.CurrentURL = b.URL
		ss.IsType = CustomServerType
	} else {
		return errors.Errorf("this server is not yet added as a custom server: %s", b.URL)
	}
	return nil
}

func (ss *Servers) GetCustomServer(url string) (*InstituteAccessServer, error) {
	if srv, ok := ss.CustomServers.Map[url]; ok {
		return srv, nil
	}
	return nil, errors.Errorf("failed to get institute access server - no custom server with URL '%s'", url)
}

func (ss *Servers) RemoveCustomServer(url string) {
	ss.CustomServers.Remove(url)
}