-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
81 lines (61 loc) · 1.79 KB
/
config.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package nginxconf
import (
"fmt"
"net/url"
)
type SiteConfigurationTemplateType string
var (
StaticSite SiteConfigurationTemplateType = "static"
ProxySite SiteConfigurationTemplateType = "proxy"
RedirectSite SiteConfigurationTemplateType = "redirect"
)
type SiteConfigurationSSLProvider interface {
SSLCertificatePath(domain string) string
SSLCertificateKeyPath(domain string) string
SSLTrustedCertificatePath(domain string) string
}
type SiteConfiguration struct {
// The domain, required
Domain string
// Alternative domains we should handle but redirect
AltDomains []string
// The template type, required
Template SiteConfigurationTemplateType
// Whether to write SSL
SSL bool
// The SSL provider
SSLProvider SiteConfigurationSSLProvider
// Proxy port, required for proxy type
ProxyPort int
// Root directory
Webroot string
// Redirect URL, required for redirect type
RedirectURL *url.URL
}
func (c *SiteConfiguration) IsStatic() bool {
return c.Template == StaticSite
}
func (c *SiteConfiguration) IsProxy() bool {
return c.Template == ProxySite
}
func (c *SiteConfiguration) IsRedirect() bool {
return c.Template == RedirectSite
}
func (c *SiteConfiguration) ProxyURL() string {
return fmt.Sprintf("http://localhost:%d", c.ProxyPort)
}
func (c *SiteConfiguration) RedirectSchemeHost() string {
if c.RedirectURL == nil {
return "https://$host"
}
return fmt.Sprintf("%s://%s", c.RedirectURL.Scheme, c.RedirectURL.Host)
}
func (c *SiteConfiguration) SSLCertificatePath() string {
return c.SSLProvider.SSLCertificatePath(c.Domain)
}
func (c *SiteConfiguration) SSLCertificateKeyPath() string {
return c.SSLProvider.SSLCertificateKeyPath(c.Domain)
}
func (c *SiteConfiguration) SSLTrustedCertificatePath() string {
return c.SSLProvider.SSLTrustedCertificatePath(c.Domain)
}