yanic/api/nodes.go

28 lines
609 B
Go
Raw Normal View History

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