Fix API inconsistencies (#404)

* fix api inconsistencies

* handling empty format cases

* code style
This commit is contained in:
Pedro Nasser
2016-12-07 17:16:48 -02:00
committed by GitHub
parent b990cba1df
commit 5367a3ef99
8 changed files with 42 additions and 23 deletions

View File

@@ -30,15 +30,15 @@ var (
type Routes []*Route
type Route struct {
AppName string `json:"app_name,omitempty"`
Path string `json:"path,omitempty"`
Image string `json:"image,omitempty"`
Memory uint64 `json:"memory,omitempty"`
Headers http.Header `json:"headers,omitempty"`
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
MaxConcurrency int `json:"max_concurrency,omitempty"`
Timeout int32 `json:"timeout,omitempty"`
AppName string `json:"app_name"`
Path string `json:"path"`
Image string `json:"image"`
Memory uint64 `json:"memory"`
Headers http.Header `json:"headers"`
Type string `json:"type"`
Format string `json:"format"`
MaxConcurrency int `json:"max_concurrency"`
Timeout int32 `json:"timeout"`
Config `json:"config"`
}
@@ -92,14 +92,26 @@ func (r *Route) Validate() error {
res = append(res, ErrRoutesValidationInvalidType)
}
if r.Format == "" {
r.Format = FormatDefault
}
if r.Format != FormatDefault && r.Format != FormatHTTP {
res = append(res, ErrRoutesValidationInvalidFormat)
}
if r.MaxConcurrency == 0 && r.Format == FormatHTTP {
if r.MaxConcurrency == 0 {
r.MaxConcurrency = 1
}
if r.Headers == nil {
r.Headers = http.Header{}
}
if r.Config == nil {
r.Config = map[string]string{}
}
if r.Timeout == 0 {
r.Timeout = defaultRouteTimeout
} else if r.Timeout < 0 {

View File

@@ -23,7 +23,7 @@ const (
const (
// FormatDefault ...
FormatDefault = ""
FormatDefault = "default"
// FormatHTTP ...
FormatHTTP = "http"
)