代码拉取完成,页面将自动刷新
package yaml
import (
"fmt"
"net/http"
"github.com/rancher/norman/httperror"
"github.com/rancher/norman/types"
"github.com/rancher/rancher/pkg/clustermanager"
)
func NewLinkHandler(proxy http.Handler, manager *clustermanager.Manager, next types.RequestHandler) types.RequestHandler {
lh := &yamlLinkHandler{
Proxy: proxy,
ClusterManager: manager,
next: next,
}
return lh.LinkHandler
}
type yamlLinkHandler struct {
Proxy http.Handler
ClusterManager *clustermanager.Manager
next types.RequestHandler
}
func (s *yamlLinkHandler) callNext(apiContext *types.APIContext, next types.RequestHandler) error {
if s.next != nil {
return s.next(apiContext, next)
} else if next != nil {
return next(apiContext, nil)
}
return httperror.NewAPIError(httperror.NotFound, "link not found")
}
func (s *yamlLinkHandler) LinkHandler(apiContext *types.APIContext, next types.RequestHandler) error {
if apiContext.Link != "yaml" {
return s.callNext(apiContext, next)
}
clusterName := s.ClusterManager.ClusterName(apiContext)
if clusterName == "" {
return httperror.NewAPIError(httperror.NotFound, "cluster not found")
}
schema := apiContext.Schemas.Schema(apiContext.Version, apiContext.Type)
if schema == nil {
return fmt.Errorf("failed to find schema " + apiContext.Type)
}
data, err := schema.Store.ByID(apiContext, schema, apiContext.ID)
if err != nil {
return err
}
link, _ := data[".selfLink"].(string)
if link == "" {
return httperror.NewAPIError(httperror.NotFound, "self link not found")
}
apiContext.Request.URL.Path = fmt.Sprintf("/k8s/clusters/%s%s", clusterName, link)
s.Proxy.ServeHTTP(apiContext.Response, apiContext.Request)
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。