コード例 #1
0
func VersionsHandler(schemas *client.Schemas, versions ...string) http.Handler {
	return ApiHandler(schemas, http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
		apiContext := GetApiContext(r)

		collection := client.GenericCollection{
			Collection: client.Collection{
				Links: map[string]string{},
			},
			Data: []interface{}{},
		}

		for i, version := range versions {
			collection.Data = append(collection.Data, client.Resource{
				Id: version,
				Links: map[string]string{
					SELF: apiContext.UrlBuilder.Version(version),
				},
				Type: "apiVersion",
			})

			if i == len(versions)-1 {
				collection.Links[LATEST] = apiContext.UrlBuilder.Version(version)
			}
		}

		apiContext.Write(&collection)
	}))
}
コード例 #2
0
ファイル: replica.go プロジェクト: th3architect/longhorn
func (s *Server) ListReplicas(rw http.ResponseWriter, req *http.Request) error {
	apiContext := api.GetApiContext(req)
	resp := client.GenericCollection{}
	resp.Data = append(resp.Data, s.Replica(apiContext))

	apiContext.Write(&resp)
	return nil
}