forked from pieterlouw/caddy-net
/
host.go
43 lines (35 loc) · 804 Bytes
/
host.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
package host
import (
"github.com/mholt/caddy"
"github.com/mholt/caddy/caddytls"
"github.com/pieterlouw/caddy-net/caddynet/netserver"
)
func init() {
caddy.RegisterPlugin("host", caddy.Plugin{
ServerType: "net",
Action: setupHost,
})
}
func setupHost(c *caddy.Controller) error {
config := netserver.GetConfig(c)
// Ignore call to setupHost if the key is not echo or proxy
if c.Key != "echo" && c.Key != "proxy" {
return nil
}
for c.Next() {
if !c.NextArg() {
return c.ArgErr()
}
config.Hostname = c.Val()
if config.TLS == nil {
config.TLS = &caddytls.Config{Hostname: c.Val()}
} else {
config.TLS.Hostname = c.Val()
}
if c.NextArg() {
// only one argument allowed
return c.ArgErr()
}
}
return nil
}