// nodeToAgentAdvert takes a etcd Node representing an AgentAdvert and returns an AgentAdvert func nodeToAgentAdvert(node *client.Node, expectedUUID string) (*defs.AgentAdvert, error) { adv := new(defs.AgentAdvert) // Marshal API data into object err := json.Unmarshal([]byte(node.Value), adv) if err != nil { log.Error("Failed to unmarshal json into agent advertisement") return nil, err } // We want to use the TTLDuration field from etcd for simplicity adv.Expires = node.TTLDuration() // The etcd key should always match the inner JSON if expectedUUID != adv.Uuid { return nil, errors.New("UUID in etcd does not match inner JSON text") } return adv, nil }