internal/agent/agent_endpoint.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package agent import ( "fmt" "net/http" "github.com/hashicorp/serf/coordinate" "github.com/hashicorp/serf/serf" ) type Self struct { Config interface{} DebugConfig map[string]interface{} Coord *coordinate.Coordinate Member serf.Member Stats map[string]map[string]string Meta map[string]string } func (s *HTTPHandlers) agentSelf(resp http.ResponseWriter, req *http.Request) (interface{}, error) { var err error if err = s.agent.GetCoordinate(); err != nil { return nil, err } config := struct { NodeName string Version string BuildDate string }{ NodeName: s.agent.Config.NodeName, // We expect the ent version to be part // of the reported version string, and that's // now part of the metadata, not the actual version. Version: s.agent.Config.VersionWithMetadata(), } return Self{ Config: config, // Coord: cs[s.agent.Config.SegmentName], // Member: s.agent.AgentLocalMember(), // Stats: s.agent.Stats(), // Meta: s.agent.State.Metadata(), }, nil } // return s.agent.Members() // func (s *HTTPHandlers) Index(resp http.ResponseWriter, req *http.Request) { func (s *HTTPHandlers) agentMembers(w http.ResponseWriter, r *http.Request) { members := s.agent.Members() json, err := s.marshalJSON(r, members) if err != nil { fmt.Println(err) w.WriteHeader(http.StatusInternalServerError) return } fmt.Fprintf(w, string(json)) }