mirror of
https://github.com/rancher/steve.git
synced 2025-04-27 02:51:10 +00:00
36 lines
796 B
Go
36 lines
796 B
Go
package common
|
|
|
|
import (
|
|
"github.com/rancher/steve/pkg/schema"
|
|
"github.com/rancher/steve/pkg/schemaserver/types"
|
|
"github.com/rancher/steve/pkg/server/store/proxy"
|
|
"k8s.io/apimachinery/pkg/api/meta"
|
|
)
|
|
|
|
func DefaultTemplate(clientGetter proxy.ClientGetter) schema.Template {
|
|
return schema.Template{
|
|
Store: proxy.NewProxyStore(clientGetter),
|
|
Formatter: Formatter,
|
|
Mapper: &DefaultColumns{},
|
|
}
|
|
}
|
|
|
|
func Formatter(request *types.APIRequest, resource *types.RawResource) {
|
|
meta, err := meta.Accessor(resource.APIObject.Object)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
selfLink := meta.GetSelfLink()
|
|
if selfLink == "" {
|
|
return
|
|
}
|
|
|
|
u := request.URLBuilder.RelativeToRoot(selfLink)
|
|
resource.Links["view"] = u
|
|
|
|
if _, ok := resource.Links["update"]; !ok {
|
|
resource.Links["update"] = u
|
|
}
|
|
}
|