fix marshalling

This commit is contained in:
Hans Hasselberg 2019-01-24 17:03:26 +01:00
parent d4790b2827
commit 7f44100101
1 changed files with 16 additions and 17 deletions

View File

@ -917,27 +917,26 @@ type HealthCheckDefinition struct {
DeregisterCriticalServiceAfter time.Duration `json:",omitempty"` DeregisterCriticalServiceAfter time.Duration `json:",omitempty"`
} }
func (d *HealthCheckDefinition) MarshalJSON() ([]byte, error) { type Alias HealthCheckDefinition
type Alias HealthCheckDefinition type ExportedHealthCheckDefinition struct {
exported := &struct { Interval string `json:",omitempty"`
Interval string Timeout string `json:",omitempty"`
Timeout string DeregisterCriticalServiceAfter string `json:",omitempty"`
DeregisterCriticalServiceAfter string
*Alias *Alias
}{ }
Interval: d.Interval.String(),
Timeout: d.Timeout.String(), func (d *HealthCheckDefinition) MarshalJSON() ([]byte, error) {
DeregisterCriticalServiceAfter: d.DeregisterCriticalServiceAfter.String(), exported := &ExportedHealthCheckDefinition{
Alias: (*Alias)(d), Alias: (*Alias)(d),
} }
if d.Interval == 0 { if d.Interval != 0 {
exported.Interval = "" exported.Interval = d.Interval.String()
} }
if d.Timeout == 0 { if d.Timeout != 0 {
exported.Timeout = "" exported.Timeout = d.Interval.String()
} }
if d.DeregisterCriticalServiceAfter == 0 { if d.DeregisterCriticalServiceAfter != 0 {
exported.DeregisterCriticalServiceAfter = "" exported.DeregisterCriticalServiceAfter = d.Interval.String()
} }
return json.Marshal(exported) return json.Marshal(exported)