Files
matchbox/api/metadata.go
Dalton Hubble 76cec40b5a api: Add metadata endpoint with plain/text KEY=val's
* Show example with a custom metadata agent in Ignition
2016-01-31 01:13:53 -08:00

31 lines
654 B
Go

package api
import (
"fmt"
"net/http"
"strings"
"golang.org/x/net/context"
)
const plainContentType = "plain/text"
func metadataHandler() ContextHandler {
fn := func(ctx context.Context, w http.ResponseWriter, req *http.Request) {
group, err := groupFromContext(ctx)
if err != nil {
http.NotFound(w, req)
return
}
w.Header().Set(contentType, plainContentType)
for key, value := range group.Metadata {
fmt.Fprintf(w, "%s=%s\n", strings.ToUpper(key), value)
}
attrs := labelsFromRequest(req)
for key, value := range attrs {
fmt.Fprintf(w, "%s=%s\n", strings.ToUpper(key), value)
}
}
return ContextHandlerFunc(fn)
}