dd291e69f4
node drain: use msgtype on txn so that events are emitted wip: encoding extension to add Node.Drain field back to API responses new approach for hiding Node.SecretID in the API, using `json` tag documented this approach in the contributing guide refactored the JSON handlers with extensions modified event stream encoding to use the go-msgpack encoders with the extensions
37 lines
819 B
Go
37 lines
819 B
Go
package structs
|
|
|
|
import (
|
|
"reflect"
|
|
|
|
"github.com/hashicorp/go-msgpack/codec"
|
|
)
|
|
|
|
// Special encoding for structs.Node, to perform the following:
|
|
// 1. provide backwards compatibility for the following fields:
|
|
// * Node.Drain
|
|
type nodeExt struct{}
|
|
|
|
// ConvertExt converts a structs.Node to a struct with the extra field, Drain
|
|
func (n nodeExt) ConvertExt(v interface{}) interface{} {
|
|
node := v.(*Node)
|
|
if node == nil {
|
|
return nil
|
|
}
|
|
type NodeAlias Node
|
|
return &struct {
|
|
*NodeAlias
|
|
Drain bool
|
|
}{
|
|
NodeAlias: (*NodeAlias)(node),
|
|
Drain: node.DrainStrategy != nil,
|
|
}
|
|
}
|
|
|
|
// UpdateExt is not used
|
|
func (n nodeExt) UpdateExt(_ interface{}, _ interface{}) {}
|
|
|
|
func RegisterJSONEncodingExtensions(h *codec.JsonHandle) *codec.JsonHandle {
|
|
h.SetInterfaceExt(reflect.TypeOf(Node{}), 1, nodeExt{})
|
|
return h
|
|
}
|