1
0
mirror of https://github.com/rancher/norman.git synced 2025-06-20 20:52:01 +00:00
norman/api/handler/list.go

37 lines
652 B
Go
Raw Normal View History

2017-11-21 20:46:30 +00:00
package handler
2017-11-11 04:44:02 +00:00
import (
"net/http"
"github.com/rancher/norman/parse"
"github.com/rancher/norman/types"
)
func ListHandler(request *types.APIContext) error {
var (
err error
data interface{}
)
store := request.Schema.Store
if store == nil {
return nil
}
if request.ID == "" {
2017-11-21 20:46:30 +00:00
opts := parse.QueryOptions(request, request.Schema)
data, err = store.List(request, request.Schema, opts)
2017-11-11 04:44:02 +00:00
} else if request.Link == "" {
data, err = store.ByID(request, request.Schema, request.ID)
} else {
return request.Schema.LinkHandler(request)
}
if err != nil {
return err
}
request.WriteResponse(http.StatusOK, data)
return nil
}