diff --git a/compose/parser.go b/compose/parser.go index ca9b8b0..7dcfd7e 100644 --- a/compose/parser.go +++ b/compose/parser.go @@ -170,18 +170,18 @@ func parseCommand(s *Service) { } // following the command type, it can be a "slice" or a simple sting, so we need to check it - switch s.RawCommand.(type) { + switch v := s.RawCommand.(type) { case string: // use shlex to parse the command - command, err := shlex.Split(s.RawCommand.(string)) + command, err := shlex.Split(v) if err != nil { log.Fatal(err) } s.Command = command case []string: - s.Command = s.RawCommand.([]string) + s.Command = v case []interface{}: - for _, v := range s.RawCommand.([]interface{}) { + for _, v := range v { s.Command = append(s.Command, v.(string)) } default: @@ -196,11 +196,11 @@ func parseEnvFiles(s *Service) { return } envfiles := make([]string, 0) - switch s.RawEnvFiles.(type) { + switch v := s.RawEnvFiles.(type) { case []string: - envfiles = s.RawEnvFiles.([]string) + envfiles = v case []interface{}: - for _, v := range s.RawEnvFiles.([]interface{}) { + for _, v := range v { envfiles = append(envfiles, v.(string)) } default: @@ -209,3 +209,28 @@ func parseEnvFiles(s *Service) { } s.EnvFiles = envfiles } + +func parseHealthCheck(s *Service) { + // HealthCheck command can be a string or slice of strings + if s.HealthCheck.RawTest == nil { + return + } + switch v := s.HealthCheck.RawTest.(type) { + case string: + var err error + s.HealthCheck.Test, err = shlex.Split(v) + if err != nil { + log.Fatal(err) + } + case []string: + s.HealthCheck.Test = v + + case []interface{}: + for _, v := range v { + s.HealthCheck.Test = append(s.HealthCheck.Test, v.(string)) + } + default: + log.Printf("%+v %T", s.HealthCheck.RawTest, s.HealthCheck.RawTest) + log.Fatal("HealthCheck type not supported") + } +} diff --git a/compose/types.go b/compose/types.go index ce77f72..f9c6238 100644 --- a/compose/types.go +++ b/compose/types.go @@ -17,11 +17,12 @@ func NewCompose() *Compose { // HealthCheck manage generic type to handle TCP, HTTP and TCP health check. type HealthCheck struct { - Test []string `yaml:"test"` - Interval string `yaml:"interval"` - Timeout string `yaml:"timeout"` - Retries int `yaml:"retries"` - StartPeriod string `yaml:"start_period"` + Test []string `yaml:"-"` + RawTest interface{} `yaml:"test"` + Interval string `yaml:"interval"` + Timeout string `yaml:"timeout"` + Retries int `yaml:"retries"` + StartPeriod string `yaml:"start_period"` } // Service represent a "service" in a docker-compose file.