api access controll
This commit is contained in:
parent
24b4e54f25
commit
255257033f
24
api/nodes.go
Normal file
24
api/nodes.go
Normal 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)
|
||||||
|
}
|
4
main.go
4
main.go
@ -46,10 +46,12 @@ func main() {
|
|||||||
if config.Webserver.Enable {
|
if config.Webserver.Enable {
|
||||||
router := httprouter.New()
|
router := httprouter.New()
|
||||||
if config.Webserver.Api.NewNode {
|
if config.Webserver.Api.NewNode {
|
||||||
|
api.NewNodes(config,router,"/api/nodess",nodes)
|
||||||
|
log.Println("api nodes started")
|
||||||
}
|
}
|
||||||
if config.Webserver.Api.Aliases {
|
if config.Webserver.Api.Aliases {
|
||||||
api.NewAliases(config,router,"/api/aliases",nodes)
|
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)))
|
router.NotFound = gziphandler.GzipHandler(http.FileServer(http.Dir(config.Webserver.Webroot)))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user