コード例 #1
0
func ResourceToMap(obj interface{}, schemas *client.Schemas) (map[string]interface{}, error) {
	result := map[string]interface{}{}
	if obj == nil {
		return result, nil
	}

	resource := getResource(obj)
	if resource == nil {
		return result, errors.New("value is not a Resource")
	}

	objMap, err := toMap(obj)
	if err != nil {
		return result, err
	}

	schema := schemas.Schema(resource.Type)
	for k, v := range objMap {
		_, ok := schema.CheckField(k)
		if !ok {
			continue
		}
		result[k] = v
	}

	return result, nil
}
コード例 #2
0
func SchemaHandler(schemas *client.Schemas) http.Handler {
	return ApiHandler(schemas, http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
		apiContext := GetApiContext(r)

		schema := schemas.Schema(mux.Vars(r)["id"])

		populateSchema(apiContext, &schema)

		apiContext.Write(&schema)
	}))
}