Ensure partition-exports kind gets marshalled

The api module has decoding functions that rely on 'kind' being present
of payloads. This is so that we can decode into the appropriate api type
for the config entry.

This commit ensures that a static kind is marshalled in responses from
Consul's api endpoints so that the api module can decode them.
This commit is contained in:
freddygv 2021-10-27 14:54:27 -06:00
parent fbcf9f3f6c
commit ac96ce6552
1 changed files with 17 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package structs
import (
"encoding/json"
"fmt"
"github.com/hashicorp/consul/acl"
@ -158,3 +159,19 @@ func (e *PartitionExportsConfigEntry) GetEnterpriseMeta() *EnterpriseMeta {
return &e.EnterpriseMeta
}
// MarshalJSON adds the Kind field so that the JSON can be decoded back into the
// correct type.
// This method is implemented on the structs type (as apposed to the api type)
// because that is what the API currently uses to return a response.
func (e *PartitionExportsConfigEntry) MarshalJSON() ([]byte, error) {
type Alias PartitionExportsConfigEntry
source := &struct {
Kind string
*Alias
}{
Kind: PartitionExports,
Alias: (*Alias)(e),
}
return json.Marshal(source)
}