fea: access in name proxy.

This commit is contained in:
Daniel Ding
2025-04-21 10:42:51 +08:00
parent 84c638ffe8
commit d8a24744d7
40 changed files with 243 additions and 213 deletions

39
pkg/api/access.go Executable file
View File

@@ -0,0 +1,39 @@
package api
import (
"net/http"
"github.com/gorilla/mux"
"github.com/luscis/openlan/pkg/cache"
"github.com/luscis/openlan/pkg/models"
"github.com/luscis/openlan/pkg/schema"
)
type Access struct {
}
func (h Access) Router(router *mux.Router) {
router.HandleFunc("/api/point", h.List).Methods("GET")
router.HandleFunc("/api/point/{id}", h.Get).Methods("GET")
}
func (h Access) List(w http.ResponseWriter, r *http.Request) {
points := make([]schema.Access, 0, 1024)
for u := range cache.Access.List() {
if u == nil {
break
}
points = append(points, models.NewAccessSchema(u))
}
ResponseJson(w, points)
}
func (h Access) Get(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
point := cache.Access.Get(vars["id"])
if point != nil {
ResponseJson(w, models.NewAccessSchema(point))
} else {
http.Error(w, vars["id"], http.StatusNotFound)
}
}