package system import "net" type NetInterface struct { Name string `json:"name" example:"eth0"` MAC string `json:"mac" example:"aa:bb:cc:dd:ee:ff"` Up bool `json:"up" doc:"Interface is administratively up"` Addresses []string `json:"addresses" doc:"Assigned addresses in CIDR notation"` } func netInfo() []NetInterface { ifaces, err := net.Interfaces() if err != nil { return nil } out := []NetInterface{} for _, ifi := range ifaces { addrs, _ := ifi.Addrs() strs := []string{} for _, a := range addrs { strs = append(strs, a.String()) } out = append(out, NetInterface{ Name: ifi.Name, MAC: ifi.HardwareAddr.String(), Up: ifi.Flags&net.FlagUp != 0, Addresses: strs, }) } return out }