mirror of
https://github.com/luscis/openlan.git
synced 2025-10-06 09:06:54 +08:00
40 lines
881 B
Go
Executable File
40 lines
881 B
Go
Executable File
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/luscis/openlan/pkg/cache"
|
|
"github.com/luscis/openlan/pkg/libol"
|
|
"github.com/luscis/openlan/pkg/models"
|
|
"github.com/luscis/openlan/pkg/schema"
|
|
)
|
|
|
|
type Output struct {
|
|
Switcher Switcher
|
|
}
|
|
|
|
func (h Output) Router(router *mux.Router) {
|
|
router.HandleFunc("/api/network/{id}/output", h.Get).Methods("GET")
|
|
router.HandleFunc("/api/network/{id}/output", h.Post).Methods("POST")
|
|
}
|
|
|
|
func (h Output) Get(w http.ResponseWriter, r *http.Request) {
|
|
vars := mux.Vars(r)
|
|
name := vars["id"]
|
|
|
|
libol.Debug("Output.Get %s")
|
|
outputs := make([]schema.Output, 0, 1024)
|
|
for l := range cache.Output.List(name) {
|
|
if l == nil {
|
|
break
|
|
}
|
|
outputs = append(outputs, models.NewOutputSchema(l))
|
|
}
|
|
ResponseJson(w, outputs)
|
|
}
|
|
|
|
func (h Output) Post(w http.ResponseWriter, r *http.Request) {
|
|
ResponseJson(w, "outputs")
|
|
}
|