-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathupstream.go
More file actions
47 lines (34 loc) · 851 Bytes
/
upstream.go
File metadata and controls
47 lines (34 loc) · 851 Bytes
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
38
39
40
41
42
43
44
45
46
47
package main
import (
"net/url"
"strings"
)
type UpstreamConfiguration struct {
Host string `yaml:"host,omitempty"`
HostURL *url.URL `yaml:"-"`
Users []string `yaml:"users,omitempty"`
Groups []string `yaml:"groups,omitempty"`
}
type UpstreamConfigurationMap map[string]*UpstreamConfiguration
func (configMap UpstreamConfigurationMap) Find(pattern string) *UpstreamConfiguration {
upstreamConfig := configMap[pattern]
if upstreamConfig == nil {
pattern = strings.TrimPrefix(pattern, "/")
upstreamConfig = configMap[pattern]
}
return upstreamConfig
}
func (c *UpstreamConfiguration) Parse() (err error) {
c.HostURL, err = url.Parse(c.Host)
return
}
func (c *UpstreamConfiguration) FindUsername(name string) string {
var user = ""
for _, u := range c.Users {
if u == name {
user = u
break
}
}
return user
}