-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelay.go
66 lines (52 loc) · 1.24 KB
/
relay.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
package config
import (
"github.com/pkg/errors"
)
// Relay config.
type Relay struct {
// Command run to start your server.
Command string `json:"command"`
// Timeout in seconds to wait for a response.
Timeout int `json:"timeout"`
// ListenTimeout in seconds when waiting for the app to bind to PORT.
ListenTimeout int `json:"listen_timeout"`
}
// Default implementation.
func (r *Relay) Default() error {
if r.Command == "" {
r.Command = "./server"
}
if r.Timeout == 0 {
r.Timeout = 15
}
if r.ListenTimeout == 0 {
r.ListenTimeout = 15
}
return nil
}
// Validate will try to perform sanity checks for this Relay configuration.
func (r *Relay) Validate() error {
if r.Command == "" {
err := errors.New("should not be empty")
return errors.Wrap(err, ".command")
}
if r.ListenTimeout <= 0 {
err := errors.New("should be greater than 0")
return errors.Wrap(err, ".listen_timeout")
}
if r.ListenTimeout > 25 {
err := errors.New("should be <= 25")
return errors.Wrap(err, ".listen_timeout")
}
if r.Timeout > 25 {
err := errors.New("should be <= 25")
return errors.Wrap(err, ".timeout")
}
return nil
}
// Override config.
func (r *Relay) Override(c *Config) {
if r.Command != "" {
c.Proxy.Command = r.Command
}
}