yanic/api/nodes.go

25 lines
522 B
Go
Raw Normal View History

2016-05-17 10:59:34 +02:00
package api
import (
"github.com/FreifunkBremen/respond-collector/models"
2016-05-29 21:41:58 +02:00
"github.com/julienschmidt/httprouter"
"net/http"
2016-05-17 10:59:34 +02:00
)
type ApiNodes struct {
2016-05-29 21:41:58 +02:00
config *models.Config
nodes *models.Nodes
2016-05-17 10:59:34 +02:00
}
2016-05-29 21:41:58 +02:00
func NewNodes(config *models.Config, router *httprouter.Router, prefix string, nodes *models.Nodes) {
2016-05-17 10:59:34 +02:00
api := &ApiNodes{
2016-05-29 21:41:58 +02:00
nodes: nodes,
2016-05-17 10:59:34 +02:00
config: config,
}
2016-05-29 21:41:58 +02:00
router.GET(prefix, api.GetAll)
2016-05-17 10:59:34 +02:00
}
func (api *ApiNodes) GetAll(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
2016-05-29 21:41:58 +02:00
jsonOutput(w, r, api.nodes.List)
2016-05-17 10:59:34 +02:00
}