本文整理匯總了Golang中k8s/io/kubernetes/pkg/runtime.IsListType函數的典型用法代碼示例。如果您正苦於以下問題:Golang IsListType函數的具體用法?Golang IsListType怎麽用?Golang IsListType使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了IsListType函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: setListSelfLink
// setListSelfLink sets the self link of a list to the base URL, then sets the self links
// on all child objects returned.
func setListSelfLink(obj runtime.Object, req *restful.Request, namer ScopeNamer) error {
if !runtime.IsListType(obj) {
return nil
}
// TODO: List SelfLink generation should return a full URL?
path, query, err := namer.GenerateListLink(req)
if err != nil {
return err
}
newURL := *req.Request.URL
newURL.Path = path
newURL.RawQuery = query
// use the path that got us here
newURL.Fragment = ""
if err := namer.SetSelfLink(obj, newURL.String()); err != nil {
glog.V(4).Infof("Unable to set self link on object: %v", err)
}
// Set self-link of objects in the list.
items, err := runtime.ExtractList(obj)
if err != nil {
return err
}
for i := range items {
if err := setSelfLink(items[i], req, namer); err != nil {
return err
}
}
return runtime.SetList(obj, items)
}
示例2: Add
func (o objects) Add(obj runtime.Object) error {
_, kind, err := o.scheme.ObjectVersionAndKind(obj)
if err != nil {
return err
}
switch {
case runtime.IsListType(obj):
if kind != "List" {
o.types[kind] = append(o.types[kind], obj)
}
list, err := runtime.ExtractList(obj)
if err != nil {
return err
}
if errs := runtime.DecodeList(list, o.decoder); len(errs) > 0 {
return errs[0]
}
for _, obj := range list {
if err := o.Add(obj); err != nil {
return err
}
}
default:
if status, ok := obj.(*api.Status); ok && status.Details != nil {
kind = status.Details.Kind
}
o.types[kind] = append(o.types[kind], obj)
}
return nil
}
示例3: PrintObj
func (s *CustomColumnsPrinter) PrintObj(obj runtime.Object, out io.Writer) error {
w := tabwriter.NewWriter(out, columnwidth, tabwidth, padding, padding_character, flags)
headers := make([]string, len(s.Columns))
for ix := range s.Columns {
headers[ix] = s.Columns[ix].Header
}
fmt.Fprintln(w, strings.Join(headers, "\t"))
parsers := make([]*jsonpath.JSONPath, len(s.Columns))
for ix := range s.Columns {
parsers[ix] = jsonpath.New(fmt.Sprintf("column%d", ix))
if err := parsers[ix].Parse(s.Columns[ix].FieldSpec); err != nil {
return err
}
}
if runtime.IsListType(obj) {
objs, err := runtime.ExtractList(obj)
if err != nil {
return err
}
for ix := range objs {
if err := s.printOneObject(objs[ix], parsers, w); err != nil {
return err
}
}
} else {
if err := s.printOneObject(obj, parsers, w); err != nil {
return err
}
}
return w.Flush()
}
示例4: filterListInTenant
func filterListInTenant(obj runtime.Object, tenant string, kind string, namer ScopeNamer) error {
var (
result = []runtime.Object{}
)
if !runtime.IsListType(obj) {
return nil
}
items, err := runtime.ExtractList(obj)
if err != nil {
return err
}
for i := range items {
if name, err := namer.ObjectTenant(items[i]); err == nil {
if tenant == name {
result = append(result, items[i])
continue
}
if name == "" {
result = append(result, items[i])
}
}
}
return runtime.SetList(obj, result)
}
示例5: PrintObj
func (s *SortingPrinter) PrintObj(obj runtime.Object, out io.Writer) error {
if !runtime.IsListType(obj) {
return s.Delegate.PrintObj(obj, out)
}
if err := s.sortObj(obj); err != nil {
return err
}
return s.Delegate.PrintObj(obj, out)
}
示例6: PrintObj
func (s *SortingPrinter) PrintObj(obj runtime.Object, out io.Writer) error {
if !runtime.IsListType(obj) {
fmt.Fprintf(out, "Not a list, skipping: %#v\n", obj)
return s.Delegate.PrintObj(obj, out)
}
if err := s.sortObj(obj); err != nil {
return err
}
return s.Delegate.PrintObj(obj, out)
}
示例7: TestIsList
func TestIsList(t *testing.T) {
tests := []struct {
obj runtime.Object
isList bool
}{
{&api.PodList{}, true},
{&api.Pod{}, false},
}
for _, item := range tests {
if e, a := item.isList, runtime.IsListType(item.obj); e != a {
t.Errorf("%v: Expected %v, got %v", reflect.TypeOf(item.obj), e, a)
}
}
}
示例8: RetrieveLatest
// RetrieveLatest updates the Object on each Info by invoking a standard client
// Get.
func RetrieveLatest(info *Info, err error) error {
if err != nil {
return err
}
if runtime.IsListType(info.Object) {
return fmt.Errorf("watch is only supported on individual resources and resource collections, but a list of resources is found")
}
if len(info.Name) == 0 {
return nil
}
if info.Namespaced() && len(info.Namespace) == 0 {
return fmt.Errorf("no namespace set on resource %s %q", info.Mapping.Resource, info.Name)
}
obj, err := NewHelper(info.Client, info.Mapping).Get(info.Namespace, info.Name)
if err != nil {
return err
}
info.Object = obj
info.ResourceVersion, _ = info.Mapping.MetadataAccessor.ResourceVersion(obj)
return nil
}
示例9: Object
// Object returns a single object representing the output of a single visit to all
// found resources. If the Builder was a singular context (expected to return a
// single resource by user input) and only a single resource was found, the resource
// will be returned as is. Otherwise, the returned resources will be part of an
// api.List. The ResourceVersion of the api.List will be set only if it is identical
// across all infos returned.
func (r *Result) Object() (runtime.Object, error) {
infos, err := r.Infos()
if err != nil {
return nil, err
}
versions := util.StringSet{}
objects := []runtime.Object{}
for _, info := range infos {
if info.Object != nil {
objects = append(objects, info.Object)
versions.Insert(info.ResourceVersion)
}
}
if len(objects) == 1 {
if r.singular {
return objects[0], nil
}
// if the item is a list already, don't create another list
if runtime.IsListType(objects[0]) {
return objects[0], nil
}
}
version := ""
if len(versions) == 1 {
version = versions.List()[0]
}
return &api.List{
ListMeta: api.ListMeta{
ResourceVersion: version,
},
Items: objects,
}, err
}