Files
matchbox/api/pixiecore.go
2015-12-16 02:21:59 -08:00

25 lines
550 B
Go

package api
import (
"encoding/json"
"log"
"net/http"
"strings"
)
const pixiecorePath = "/v1/boot/"
// pixiecoreHandler implements the Pixiecore API Server Spec.
func pixiecoreHandler(bootConfigs BootConfigProvider) http.Handler {
fn := func(w http.ResponseWriter, req *http.Request) {
remainder := strings.TrimPrefix(req.URL.String(), pixiecorePath)
bootConfig, err := bootConfigs.Get(remainder)
if err != nil {
http.Error(w, err.Error(), 404)
return
}
json.NewEncoder(w).Encode(bootConfig)
}
return http.HandlerFunc(fn)
}