From 255257033f6f78a64081f22ef634617c75a92104 Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Tue, 17 May 2016 10:59:34 +0200 Subject: [PATCH] api access controll --- api/nodes.go | 24 ++++++++++++++++++++++++ main.go | 4 +++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 api/nodes.go diff --git a/api/nodes.go b/api/nodes.go new file mode 100644 index 0000000..a59ec01 --- /dev/null +++ b/api/nodes.go @@ -0,0 +1,24 @@ +package api + +import ( + "net/http" + "github.com/julienschmidt/httprouter" + "github.com/FreifunkBremen/respond-collector/models" +) + +type ApiNodes struct { + config *models.Config + nodes *models.Nodes +} + +func NewNodes (config *models.Config, router *httprouter.Router,prefix string,nodes *models.Nodes) { + api := &ApiNodes{ + nodes: nodes, + config: config, + } + router.GET(prefix, api.GetAll) +} + +func (api *ApiNodes) GetAll(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { + jsonOutput(w,r,api.nodes.List) +} diff --git a/main.go b/main.go index 57fd286..6dd54a1 100644 --- a/main.go +++ b/main.go @@ -46,10 +46,12 @@ func main() { if config.Webserver.Enable { router := httprouter.New() if config.Webserver.Api.NewNode { + api.NewNodes(config,router,"/api/nodess",nodes) + log.Println("api nodes started") } if config.Webserver.Api.Aliases { api.NewAliases(config,router,"/api/aliases",nodes) - log.Println("api started") + log.Println("api aliases started") } router.NotFound = gziphandler.GzipHandler(http.FileServer(http.Dir(config.Webserver.Webroot)))