1
0
mirror of https://github.com/rancher/steve.git synced 2025-04-28 03:10:32 +00:00
steve/pkg/resources/common/formatter.go
Darren Shepherd fab677b2ec Steve!
2019-09-11 14:05:00 -07:00

32 lines
842 B
Go

package common
import (
"github.com/rancher/steve/pkg/resources/schema"
"github.com/rancher/norman/pkg/store/proxy"
"github.com/rancher/norman/pkg/types"
"github.com/rancher/norman/pkg/types/convert"
"github.com/rancher/norman/pkg/types/values"
)
func Register(collection *schema.Collection, clientGetter proxy.ClientGetter) {
collection.AddTemplate(&schema.Template{
Store: proxy.NewProxyStore(clientGetter),
Formatter: Formatter,
Mapper: &DefaultColumns{},
})
}
func Formatter(request *types.APIRequest, resource *types.RawResource) {
selfLink := convert.ToString(values.GetValueN(resource.Values, "metadata", "selfLink"))
if selfLink == "" {
return
}
u := request.URLBuilder.RelativeToRoot(selfLink)
resource.Links["view"] = u
if _, ok := resource.Links["update"]; ok {
resource.Links["update"] = u
}
}