Files
openlan/pkg/api/neighbor.go
2022-07-29 23:38:54 +08:00

28 lines
592 B
Go
Executable File

package api
import (
"github.com/gorilla/mux"
"github.com/luscis/openlan/pkg/cache"
"github.com/luscis/openlan/pkg/models"
"github.com/luscis/openlan/pkg/schema"
"net/http"
)
type Neighbor struct {
}
func (h Neighbor) Router(router *mux.Router) {
router.HandleFunc("/api/neighbor", h.List).Methods("GET")
}
func (h Neighbor) List(w http.ResponseWriter, r *http.Request) {
neighbors := make([]schema.Neighbor, 0, 1024)
for n := range cache.Neighbor.List() {
if n == nil {
break
}
neighbors = append(neighbors, models.NewNeighborSchema(n))
}
ResponseJson(w, neighbors)
}