github.com/orangenpresse/up@v0.6.0/config/relay.go (about) 1 package config 2 3 import ( 4 "github.com/pkg/errors" 5 ) 6 7 // Relay config. 8 type Relay struct { 9 // Command run to start your server. 10 Command string `json:"command"` 11 12 // Backoff configuration. 13 Backoff Backoff `json:"backoff"` 14 15 // Retry enables idempotent request retries. Enabled by default. 16 Retry *bool `json:"retry"` 17 18 // Timeout in seconds to wait for a response. 19 // This is also taken into account when performing 20 // retries, as to not exceed the limit. 21 Timeout int `json:"timeout"` 22 23 // ListenTimeout in seconds when waiting for 24 // the application to bind to PORT. 25 ListenTimeout int `json:"listen_timeout"` 26 27 // ShutdownTimeout in seconds to wait after 28 // sending a SIGINT before sending a SIGKILL. 29 ShutdownTimeout int `json:"shutdown_timeout"` 30 31 // platform is a currently unexported designation of the target deploy platform for this Relay 32 platform string 33 } 34 35 // Default implementation. 36 func (r *Relay) Default() error { 37 if r.Command == "" { 38 r.Command = "./server" 39 } 40 41 if r.Timeout == 0 { 42 r.Timeout = 15 43 } 44 45 if r.ListenTimeout == 0 { 46 r.ListenTimeout = 15 47 } 48 49 if r.ShutdownTimeout == 0 { 50 r.ShutdownTimeout = 15 51 } 52 53 if err := r.Backoff.Default(); err != nil { 54 return errors.Wrap(err, ".backoff") 55 } 56 57 if r.Retry != nil && !*r.Retry { 58 r.Backoff.Attempts = 0 59 } 60 61 if r.platform == "" { 62 r.platform = "lambda" 63 } 64 65 return nil 66 } 67 68 // Validate will try to perform sanity checks for this Relay configuration. 69 func (r *Relay) Validate() error { 70 if r.Command == "" { 71 err := errors.New("should not be empty") 72 return errors.Wrap(err, ".command") 73 } 74 75 if r.platform != "lambda" { 76 err := errors.New("internal consistency error, platform should be lambda") 77 return errors.Wrap(err, ".platform") 78 } 79 80 if r.ListenTimeout <= 0 { 81 err := errors.New("should be greater than 0") 82 return errors.Wrap(err, ".listen_timeout") 83 } 84 85 if r.platform == "lambda" && r.ListenTimeout > 25 { 86 err := errors.New("should be <= 25") 87 return errors.Wrap(err, ".listen_timeout") 88 } 89 90 if r.platform == "lambda" && r.Timeout > 25 { 91 err := errors.New("should be <= 25") 92 return errors.Wrap(err, ".timeout") 93 } 94 95 if r.ShutdownTimeout < 0 { 96 err := errors.New("should be greater than 0") 97 return errors.Wrap(err, ".shutdown_timeout") 98 } 99 100 return nil 101 } 102 103 // Override config. 104 func (r *Relay) Override(c *Config) { 105 if r.Command != "" { 106 c.Proxy.Command = r.Command 107 } 108 }