VictoriaMetrics/lib/promscrape/discovery/consul/agent.go
2023-05-08 23:43:59 -07:00

40 lines
825 B
Go

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
Member AgentMember
Meta map[string]string
}
// AgentConfig is Consul agent config.
//
// See https://www.consul.io/api/agent.html#read-configuration
type AgentConfig struct {
Datacenter string
NodeName string
}
// AgentMember is Consul agent member info.
//
// See https://www.consul.io/api/agent.html#read-configuration
type AgentMember struct {
Addr string
}
// ParseAgent parses Consul agent information from bytes.
func ParseAgent(data []byte) (*Agent, error) {
var a Agent
if err := json.Unmarshal(data, &a); err != nil {
return nil, fmt.Errorf("cannot unmarshal agent info from %q: %w", data, err)
}
return &a, nil
}