2020-05-04 19:48:02 +02:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Agent is Consul agent.
|
|
|
|
//
|
|
|
|
// See https://www.consul.io/api/agent.html#read-configuration
|
|
|
|
type Agent struct {
|
|
|
|
Config AgentConfig
|
2023-05-04 11:36:21 +02:00
|
|
|
Member AgentMember
|
|
|
|
Meta map[string]string
|
2020-05-04 19:48:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// AgentConfig is Consul agent config.
|
|
|
|
//
|
|
|
|
// See https://www.consul.io/api/agent.html#read-configuration
|
|
|
|
type AgentConfig struct {
|
|
|
|
Datacenter string
|
2023-05-04 11:36:21 +02:00
|
|
|
NodeName string
|
2020-05-04 19:48:02 +02:00
|
|
|
}
|
|
|
|
|
2023-05-04 11:36:21 +02:00
|
|
|
// AgentMember is Consul agent member info.
|
|
|
|
//
|
|
|
|
// See https://www.consul.io/api/agent.html#read-configuration
|
|
|
|
type AgentMember struct {
|
|
|
|
Addr string
|
|
|
|
}
|
|
|
|
|
2023-05-09 08:40:11 +02:00
|
|
|
// ParseAgent parses Consul agent information from data.
|
2023-05-04 11:36:21 +02:00
|
|
|
func ParseAgent(data []byte) (*Agent, error) {
|
2020-05-04 19:48:02 +02:00
|
|
|
var a Agent
|
|
|
|
if err := json.Unmarshal(data, &a); err != nil {
|
2020-06-30 21:58:18 +02:00
|
|
|
return nil, fmt.Errorf("cannot unmarshal agent info from %q: %w", data, err)
|
2020-05-04 19:48:02 +02:00
|
|
|
}
|
|
|
|
return &a, nil
|
|
|
|
}
|