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"`
}
func (d *HealthCheckDefinition) MarshalJSON() ([]byte, error) {
type Alias HealthCheckDefinition
exported := &struct {
Interval string
Timeout string
DeregisterCriticalServiceAfter string
type Alias HealthCheckDefinition
type ExportedHealthCheckDefinition struct {
Interval string `json:",omitempty"`
Timeout string `json:",omitempty"`
DeregisterCriticalServiceAfter string `json:",omitempty"`
*Alias
}{
Interval: d.Interval.String(),
Timeout: d.Timeout.String(),
DeregisterCriticalServiceAfter: d.DeregisterCriticalServiceAfter.String(),
}
func (d *HealthCheckDefinition) MarshalJSON() ([]byte, error) {
exported := &ExportedHealthCheckDefinition{
Alias: (*Alias)(d),
}
if d.Interval == 0 {
exported.Interval = ""
if d.Interval != 0 {
exported.Interval = d.Interval.String()
}
if d.Timeout == 0 {
exported.Timeout = ""
if d.Timeout != 0 {
exported.Timeout = d.Interval.String()
}
if d.DeregisterCriticalServiceAfter == 0 {
exported.DeregisterCriticalServiceAfter = ""
if d.DeregisterCriticalServiceAfter != 0 {
exported.DeregisterCriticalServiceAfter = d.Interval.String()
}
return json.Marshal(exported)