Populate 'Kind' field in all API types being returned.

This commit is contained in:
Brendan Burns 2014-06-07 21:07:20 -07:00
parent a70141307a
commit ef7cce5dad
5 changed files with 16 additions and 6 deletions

View File

@ -130,6 +130,7 @@ type TaskTemplate struct {
// ServiceList holds a list of services // ServiceList holds a list of services
type ServiceList struct { type ServiceList struct {
JSONBase
Items []Service `json:"items" yaml:"items"` Items []Service `json:"items" yaml:"items"`
} }

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
// Package apiserver is ... // Package apiserver contains the code that provides a RESTful api service
package apiserver package apiserver
import ( import (
@ -50,13 +50,14 @@ type Status struct {
// TODO: consider migrating this to go-restful which is a more full-featured version of the same thing. // TODO: consider migrating this to go-restful which is a more full-featured version of the same thing.
type ApiServer struct { type ApiServer struct {
prefix string prefix string
apiName string
storage map[string]RESTStorage storage map[string]RESTStorage
} }
// New creates a new ApiServer object. // New creates a new ApiServer object.
// 'storage' contains a map of handlers. // 'storage' contains a map of handlers.
// 'prefix' is the hosting path prefix. // 'prefix' is the hosting path prefix.
func New(storage map[string]RESTStorage, prefix string) *ApiServer { func New(storage map[string]RESTStorage, prefix, apiName string) *ApiServer {
return &ApiServer{ return &ApiServer{
storage: storage, storage: storage,
prefix: prefix, prefix: prefix,

View File

@ -35,7 +35,7 @@ func MakeControllerRegistryStorage(registry ControllerRegistry) apiserver.RESTSt
} }
func (storage *ControllerRegistryStorage) List(*url.URL) (interface{}, error) { func (storage *ControllerRegistryStorage) List(*url.URL) (interface{}, error) {
var result ReplicationControllerList result := ReplicationControllerList{JSONBase: JSONBase{Kind: "cluster#replicationControllerList"}}
controllers, err := storage.registry.ListControllers() controllers, err := storage.registry.ListControllers()
if err == nil { if err == nil {
result = ReplicationControllerList{ result = ReplicationControllerList{
@ -46,7 +46,9 @@ func (storage *ControllerRegistryStorage) List(*url.URL) (interface{}, error) {
} }
func (storage *ControllerRegistryStorage) Get(id string) (interface{}, error) { func (storage *ControllerRegistryStorage) Get(id string) (interface{}, error) {
return storage.registry.GetController(id) controller, err := storage.registry.GetController(id)
controller.Kind = "cluster#replicationController"
return controller, err
} }
func (storage *ControllerRegistryStorage) Delete(id string) error { func (storage *ControllerRegistryStorage) Delete(id string) error {

View File

@ -60,11 +60,15 @@ func GetServiceEnvironmentVariables(registry ServiceRegistry, machine string) ([
} }
func (sr *ServiceRegistryStorage) List(*url.URL) (interface{}, error) { func (sr *ServiceRegistryStorage) List(*url.URL) (interface{}, error) {
return sr.registry.ListServices() list, err := sr.registry.ListServices()
list.Kind = "cluster#serviceList"
return list, err
} }
func (sr *ServiceRegistryStorage) Get(id string) (interface{}, error) { func (sr *ServiceRegistryStorage) Get(id string) (interface{}, error) {
return sr.registry.GetService(id) service, err := sr.registry.GetService(id)
service.Kind = "cluster#service"
return service, err
} }
func (sr *ServiceRegistryStorage) Delete(id string) error { func (sr *ServiceRegistryStorage) Delete(id string) error {

View File

@ -76,6 +76,7 @@ func (storage *TaskRegistryStorage) List(url *url.URL) (interface{}, error) {
Items: tasks, Items: tasks,
} }
} }
result.Kind = "cluster#taskList"
return result, err return result, err
} }
@ -89,6 +90,7 @@ func (storage *TaskRegistryStorage) Get(id string) (interface{}, error) {
return task, err return task, err
} }
task.CurrentState.Info = info task.CurrentState.Info = info
task.Kind = "cluster#task"
return task, err return task, err
} }