|
| 1 | +/* |
| 2 | + Copyright 2020 The Compose Specification Authors. |
| 3 | +
|
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + See the License for the specific language governing permissions and |
| 14 | + limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package types |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | +) |
| 22 | + |
| 23 | +// HealthCheckConfig the healthcheck configuration for a service |
| 24 | +type HealthCheckConfig struct { |
| 25 | + Test HealthCheckTest `yaml:"test,omitempty" json:"test,omitempty"` |
| 26 | + Timeout *Duration `yaml:"timeout,omitempty" json:"timeout,omitempty"` |
| 27 | + Interval *Duration `yaml:"interval,omitempty" json:"interval,omitempty"` |
| 28 | + Retries *uint64 `yaml:"retries,omitempty" json:"retries,omitempty"` |
| 29 | + StartPeriod *Duration `yaml:"start_period,omitempty" json:"start_period,omitempty"` |
| 30 | + StartInterval *Duration `yaml:"start_interval,omitempty" json:"start_interval,omitempty"` |
| 31 | + Disable bool `yaml:"disable,omitempty" json:"disable,omitempty"` |
| 32 | + |
| 33 | + Extensions Extensions `yaml:"#extensions,inline" json:"-"` |
| 34 | +} |
| 35 | + |
| 36 | +// HealthCheckTest is the command run to test the health of a service |
| 37 | +type HealthCheckTest []string |
| 38 | + |
| 39 | +func (l *HealthCheckTest) DecodeMapstructure(value interface{}) error { |
| 40 | + switch v := value.(type) { |
| 41 | + case string: |
| 42 | + *l = []string{"CMD-SHELL", v} |
| 43 | + case []interface{}: |
| 44 | + seq := make([]string, len(v)) |
| 45 | + for i, e := range v { |
| 46 | + seq[i] = e.(string) |
| 47 | + } |
| 48 | + *l = seq |
| 49 | + default: |
| 50 | + return fmt.Errorf("unexpected value type %T for healthcheck.test", value) |
| 51 | + } |
| 52 | + return nil |
| 53 | +} |
0 commit comments