github.com/yggdrasil-network/yggdrasil-go@v0.5.6/src/multicast/admin.go (about) 1 package multicast 2 3 import ( 4 "encoding/json" 5 6 "github.com/yggdrasil-network/yggdrasil-go/src/admin" 7 ) 8 9 type GetMulticastInterfacesRequest struct{} 10 type GetMulticastInterfacesResponse struct { 11 Interfaces []string `json:"multicast_interfaces"` 12 } 13 14 func (m *Multicast) getMulticastInterfacesHandler(req *GetMulticastInterfacesRequest, res *GetMulticastInterfacesResponse) error { 15 res.Interfaces = []string{} 16 for _, v := range m.Interfaces() { 17 res.Interfaces = append(res.Interfaces, v.Name) 18 } 19 return nil 20 } 21 22 func (m *Multicast) SetupAdminHandlers(a *admin.AdminSocket) { 23 _ = a.AddHandler( 24 "getMulticastInterfaces", "Show which interfaces multicast is enabled on", []string{}, 25 func(in json.RawMessage) (interface{}, error) { 26 req := &GetMulticastInterfacesRequest{} 27 res := &GetMulticastInterfacesResponse{} 28 if err := json.Unmarshal(in, &req); err != nil { 29 return nil, err 30 } 31 if err := m.getMulticastInterfacesHandler(req, res); err != nil { 32 return nil, err 33 } 34 return res, nil 35 }, 36 ) 37 }