api access controll

This commit is contained in:
Martin Geno 2016-05-17 10:59:34 +02:00
parent 24b4e54f25
commit 255257033f
2 changed files with 27 additions and 1 deletions

24
api/nodes.go Normal file
View File

@ -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)
}

View File

@ -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)))