refactor code from restful namer

Some codes are replaced because they will never run.
pull/6/head
Cao Shufeng 2017-04-14 16:52:42 +08:00
parent eda8e12723
commit 939b962975
1 changed files with 8 additions and 11 deletions

View File

@ -46,7 +46,7 @@ type ScopeNamer interface {
// GenerateLink creates an encoded URI for a given runtime object that represents the canonical path // GenerateLink creates an encoded URI for a given runtime object that represents the canonical path
// and query. // and query.
GenerateLink(req *http.Request, obj runtime.Object) (uri string, err error) GenerateLink(req *http.Request, obj runtime.Object) (uri string, err error)
// GenerateLink creates an encoded URI for a list that represents the canonical path and query. // GenerateListLink creates an encoded URI for a list that represents the canonical path and query.
GenerateListLink(req *http.Request) (uri string, err error) GenerateListLink(req *http.Request) (uri string, err error)
} }
@ -91,22 +91,19 @@ func (n ContextBasedNaming) Name(req *http.Request) (namespace, name string, err
} }
func (n ContextBasedNaming) GenerateLink(req *http.Request, obj runtime.Object) (uri string, err error) { func (n ContextBasedNaming) GenerateLink(req *http.Request, obj runtime.Object) (uri string, err error) {
namespace, name, err := n.ObjectName(obj)
if err != nil {
return "", err
}
requestInfo, ok := request.RequestInfoFrom(n.GetContext(req)) requestInfo, ok := request.RequestInfoFrom(n.GetContext(req))
if !ok { if !ok {
return "", fmt.Errorf("missing requestInfo") return "", fmt.Errorf("missing requestInfo")
} }
if len(namespace) == 0 && len(name) == 0 { namespace, name, err := n.ObjectName(obj)
if len(requestInfo.Name) == 0 { if err == errEmptyName && len(requestInfo.Name) > 0 {
return "", errEmptyName
}
namespace = requestInfo.Namespace
name = requestInfo.Name name = requestInfo.Name
} else if err != nil {
return "", err
}
if len(namespace) == 0 && len(requestInfo.Namespace) > 0 {
namespace = requestInfo.Namespace
} }
if n.ClusterScoped { if n.ClusterScoped {