1
0
mirror of https://github.com/rancher/steve.git synced 2025-06-05 13:12:29 +00:00
steve/pkg/resources/common/formatter.go

32 lines
842 B
Go
Raw Normal View History

2019-08-13 23:36:03 +00:00
package common
import (
2019-09-11 21:05:00 +00:00
"github.com/rancher/steve/pkg/resources/schema"
2019-08-13 23:36:03 +00:00
"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"
)
2019-08-13 23:36:03 +00:00
func Register(collection *schema.Collection, clientGetter proxy.ClientGetter) {
collection.AddTemplate(&schema.Template{
Store: proxy.NewProxyStore(clientGetter),
Formatter: Formatter,
2019-08-14 18:08:34 +00:00
Mapper: &DefaultColumns{},
2019-08-13 23:36:03 +00:00
})
}
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
}
}