當前位置: 首頁>>代碼示例>>Golang>>正文


Golang GroupVersion.WithKind方法代碼示例

本文整理匯總了Golang中github.com/jordic/k8s/cloudsqlip/Godeps/_workspace/src/k8s/io/kubernetes/pkg/api/unversioned.GroupVersion.WithKind方法的典型用法代碼示例。如果您正苦於以下問題:Golang GroupVersion.WithKind方法的具體用法?Golang GroupVersion.WithKind怎麽用?Golang GroupVersion.WithKind使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/jordic/k8s/cloudsqlip/Godeps/_workspace/src/k8s/io/kubernetes/pkg/api/unversioned.GroupVersion的用法示例。


在下文中一共展示了GroupVersion.WithKind方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: AddKnownTypes

// AddKnownTypes registers all types passed in 'types' as being members of version 'version'.
// Encode() will refuse objects unless their type has been registered with AddKnownTypes.
// All objects passed to types should be pointers to structs. The name that go reports for
// the struct becomes the "kind" field when encoding.
func (s *Scheme) AddKnownTypes(gv unversioned.GroupVersion, types ...interface{}) {
	for _, obj := range types {
		t := reflect.TypeOf(obj)
		if t.Kind() != reflect.Ptr {
			panic("All types must be pointers to structs.")
		}
		t = t.Elem()
		if t.Kind() != reflect.Struct {
			panic("All types must be pointers to structs.")
		}

		gvk := gv.WithKind(t.Name())
		s.gvkToType[gvk] = t
		s.typeToGVK[t] = append(s.typeToGVK[t], gvk)
	}
}
開發者ID:jordic,項目名稱:k8s,代碼行數:20,代碼來源:scheme.go


注:本文中的github.com/jordic/k8s/cloudsqlip/Godeps/_workspace/src/k8s/io/kubernetes/pkg/api/unversioned.GroupVersion.WithKind方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。