-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtypes.go
46 lines (40 loc) · 1.08 KB
/
types.go
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
package main
import (
"errors"
"fmt"
"sync"
)
var validResurcesMap = map[string]bool{
"domains": true,
}
// AngaGoConf holds the reverse proxy configuration
type AngaGoConf struct {
mu sync.Mutex
APIVersion string `yaml:"apiVersion" json:"api_version"`
APINamespace string `yaml:"apiNamespace" json:"api_namespace"`
Kind string `yaml:"kind" json:"kind"`
Meta struct {
ShortName string `yaml:"shortName" json:"short_name"`
} `yaml:"meta" json:"meta"`
TLS bool `yaml:"tls" json:"tls"`
Domains map[string]string `yaml:"domains" json:"domains"`
}
// TargetURL returns target proxy url
func (a *AngaGoConf) TargetURL(host string) (string, error) {
a.mu.Lock()
targetURL, ok := a.Domains[host]
if !ok {
a.mu.Unlock()
return "", errors.New("invalid domain")
}
a.mu.Unlock()
return targetURL, nil
}
// AbsTargetURL appends a valid scheme with targetURL based on configuration
func (a *AngaGoConf) AbsTargetURL(targetURL string) string {
scheme := "http"
if a.TLS {
scheme = "https"
}
return fmt.Sprintf("%s://%s", scheme, targetURL)
}