本文整理汇总了Golang中k8s/io/gengo/namer.IC函数的典型用法代码示例。如果您正苦于以下问题:Golang IC函数的具体用法?Golang IC怎么用?Golang IC使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IC函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GenerateType
func (g *genFakeForGroup) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "$", "$")
const pkgTestingCore = "k8s.io/kubernetes/pkg/client/testing/core"
const pkgRESTClient = "k8s.io/kubernetes/pkg/client/restclient"
m := map[string]interface{}{
"group": g.group,
"Group": namer.IC(g.group),
"Fake": c.Universe.Type(types.Name{Package: pkgTestingCore, Name: "Fake"}),
"RESTClient": c.Universe.Type(types.Name{Package: pkgRESTClient, Name: "RESTClient"}),
}
sw.Do(groupClientTemplate, m)
for _, t := range g.types {
wrapper := map[string]interface{}{
"type": t,
"Group": namer.IC(g.group),
"realClientPackage": filepath.Base(g.realClientPath),
}
namespaced := !extractBoolTagOrDie("nonNamespaced", t.SecondClosestCommentLines)
if namespaced {
sw.Do(getterImplNamespaced, wrapper)
} else {
sw.Do(getterImplNonNamespaced, wrapper)
}
}
sw.Do(getRESTClient, m)
return sw.Error()
}
示例2: GenerateType
func (g *informerGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "$", "$")
glog.V(5).Infof("processing type %v", t)
//listerPackage := "k8s.io/kubernetes/pkg/client/listers/" + g.groupVersion.Group.NonEmpty() + "/" + strings.ToLower(g.groupVersion.Version.NonEmpty())
listerPackage := fmt.Sprintf("%s/%s/%s", g.listersPackage, g.groupVersion.Group.NonEmpty(), strings.ToLower(g.groupVersion.Version.NonEmpty()))
var (
clientSetInterface, namespaceAll *types.Type
informerFor string
)
if len(g.groupVersion.Version) == 0 {
clientSetInterface = c.Universe.Type(types.Name{Package: g.internalClientSetPackage, Name: "Interface"})
namespaceAll = c.Universe.Type(apiNamespaceAll)
informerFor = "InternalInformerFor"
} else {
clientSetInterface = c.Universe.Type(types.Name{Package: g.versionedClientSetPackage, Name: "Interface"})
namespaceAll = c.Universe.Type(v1NamespaceAll)
informerFor = "VersionedInformerFor"
}
m := map[string]interface{}{
"apiScheme": c.Universe.Type(apiScheme),
"cacheIndexers": c.Universe.Type(cacheIndexers),
"cacheListWatch": c.Universe.Type(cacheListWatch),
"cacheMetaNamespaceIndexFunc": c.Universe.Function(cacheMetaNamespaceIndexFunc),
"cacheNamespaceIndex": c.Universe.Variable(cacheNamespaceIndex),
"cacheNewSharedIndexInformer": c.Universe.Function(cacheNewSharedIndexInformer),
"cacheSharedIndexInformer": c.Universe.Type(cacheSharedIndexInformer),
"clientSetInterface": clientSetInterface,
"group": namer.IC(g.groupVersion.Group.NonEmpty()),
"informerFor": informerFor,
"interfacesSharedInformerFactory": c.Universe.Type(interfacesSharedInformerFactory),
"listOptions": c.Universe.Type(listOptions),
"lister": c.Universe.Type(types.Name{Package: listerPackage, Name: t.Name.Name + "Lister"}),
"namespaceAll": namespaceAll,
"namespaced": !extractBoolTagOrDie("nonNamespaced", t.SecondClosestCommentLines),
"newLister": c.Universe.Function(types.Name{Package: listerPackage, Name: "New" + t.Name.Name + "Lister"}),
"runtimeObject": c.Universe.Type(runtimeObject),
"timeDuration": c.Universe.Type(timeDuration),
"type": t,
"v1ListOptions": c.Universe.Type(v1ListOptions),
"version": namer.IC(g.groupVersion.Version.String()),
"watchInterface": c.Universe.Type(watchInterface),
}
sw.Do(typeInformerInterface, m)
sw.Do(typeInformerStruct, m)
if len(g.groupVersion.Version) == 0 {
sw.Do(typeInformerConstructorInternal, m)
} else {
sw.Do(typeInformerConstructorVersioned, m)
}
sw.Do(typeInformerInformer, m)
sw.Do(typeInformerLister, m)
return sw.Error()
}
示例3: ToGroupVersionPackages
// ToGroupVersionPackages is a helper function used by generators for groups.
func ToGroupVersionPackages(groups []GroupVersions) []GroupVersionPackage {
var groupVersionPackages []GroupVersionPackage
for _, group := range groups {
defaultVersion := defaultVersion(group.Versions)
for _, version := range group.Versions {
groupVersionPackages = append(groupVersionPackages, GroupVersionPackage{
Group: Group(namer.IC(group.Group.NonEmpty())),
Version: Version(namer.IC(version.String())),
GroupVersion: namer.IC(group.Group.NonEmpty()) + namer.IC(version.String()),
PackageName: strings.ToLower(version.NonEmpty() + group.Group.NonEmpty()),
IsDefaultVersion: version == defaultVersion && version != "",
})
}
}
return groupVersionPackages
}
示例4: GenerateType
func (g *genClientset) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
// TODO: We actually don't need any type information to generate the clientset,
// perhaps we can adapt the go2ild framework to this kind of usage.
sw := generator.NewSnippetWriter(w, c, "$", "$")
sw.Do(common, nil)
sw.Do(checkImpl, nil)
type arg struct {
Group string
PackageName string
}
allGroups := []arg{}
for _, gv := range g.groupVersions {
group := normalization.BeforeFirstDot(normalization.Group(gv.Group))
version := normalization.Version(gv.Version)
allGroups = append(allGroups, arg{namer.IC(group), version + group})
}
for _, g := range allGroups {
sw.Do(clientsetInterfaceImplTemplate, g)
}
return sw.Error()
}
示例5: GenerateType
func (g *genericGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "{{", "}}")
groups := []group{}
schemeGVs := make(map[*version]*types.Type)
orderer := namer.Orderer{Namer: namer.NewPrivateNamer(0)}
for _, groupVersions := range g.groupVersions {
group := group{
Name: namer.IC(groupVersions.Group.NonEmpty()),
Versions: []*version{},
}
for _, v := range groupVersions.Versions {
gv := clientgentypes.GroupVersion{Group: groupVersions.Group, Version: v}
version := &version{
Name: namer.IC(v.NonEmpty()),
Resources: orderer.OrderTypes(g.typesForGroupVersion[gv]),
}
schemeGVs[version] = c.Universe.Variable(types.Name{Package: g.typesForGroupVersion[gv][0].Name.Package, Name: "SchemeGroupVersion"})
group.Versions = append(group.Versions, version)
}
sort.Sort(versionSort(group.Versions))
groups = append(groups, group)
}
sort.Sort(groupSort(groups))
m := map[string]interface{}{
"cacheGenericLister": c.Universe.Type(cacheGenericLister),
"cacheNewGenericLister": c.Universe.Function(cacheNewGenericLister),
"cacheSharedIndexInformer": c.Universe.Type(cacheSharedIndexInformer),
"groups": groups,
"schemeGVs": schemeGVs,
"schemaGroupResource": c.Universe.Type(schemaGroupResource),
"schemaGroupVersionResource": c.Universe.Type(schemaGroupVersionResource),
}
sw.Do(genericInformer, m)
sw.Do(forResource, m)
return sw.Error()
}
示例6: GenerateType
func (g *groupInterfaceGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "$", "$")
versions := make([]versionData, 0, len(g.groupVersions.Versions))
for _, version := range g.groupVersions.Versions {
gv := clientgentypes.GroupVersion{Group: g.groupVersions.Group, Version: version}
versionPackage := filepath.Join(g.outputPackage, strings.ToLower(gv.Version.NonEmpty()))
iface := c.Universe.Type(types.Name{Package: versionPackage, Name: "Interface"})
versions = append(versions, versionData{
Name: namer.IC(version.NonEmpty()),
Interface: iface,
New: c.Universe.Function(types.Name{Package: versionPackage, Name: "New"}),
})
}
m := map[string]interface{}{
"interfacesSharedInformerFactory": c.Universe.Type(interfacesSharedInformerFactory),
"versions": versions,
}
sw.Do(groupTemplate, m)
return sw.Error()
}
示例7: GenerateType
// GenerateType makes the body of a file implementing the individual typed client for type t.
func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "$", "$")
pkg := filepath.Base(t.Name.Package)
const pkgTestingCore = "k8s.io/kubernetes/pkg/client/testing/core"
namespaced := !extractBoolTagOrDie("nonNamespaced", t.SecondClosestCommentLines)
canonicalGroup := g.group
if canonicalGroup == "core" {
canonicalGroup = ""
}
groupName := g.group
if g.group == "core" {
groupName = ""
}
// allow user to define a group name that's different from the one parsed from the directory.
p := c.Universe.Package(g.inputPackage)
if override := types.ExtractCommentTags("+", p.DocComments)["groupName"]; override != nil {
groupName = override[0]
}
m := map[string]interface{}{
"type": t,
"package": pkg,
"Package": namer.IC(pkg),
"namespaced": namespaced,
"Group": namer.IC(g.group),
"GroupVersion": namer.IC(g.group) + namer.IC(g.version),
"group": canonicalGroup,
"groupName": groupName,
"version": g.version,
"watchInterface": c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/watch", Name: "Interface"}),
"GroupVersionResource": c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/runtime/schema", Name: "GroupVersionResource"}),
"PatchType": c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/api", Name: "PatchType"}),
"Everything": c.Universe.Function(types.Name{Package: "k8s.io/kubernetes/pkg/labels", Name: "Everything"}),
"NewRootListAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewRootListAction"}),
"NewListAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewListAction"}),
"NewRootGetAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewRootGetAction"}),
"NewGetAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewGetAction"}),
"NewRootDeleteAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewRootDeleteAction"}),
"NewDeleteAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewDeleteAction"}),
"NewRootDeleteCollectionAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewRootDeleteCollectionAction"}),
"NewDeleteCollectionAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewDeleteCollectionAction"}),
"NewRootUpdateAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewRootUpdateAction"}),
"NewUpdateAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewUpdateAction"}),
"NewRootCreateAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewRootCreateAction"}),
"NewCreateAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewCreateAction"}),
"NewRootWatchAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewRootWatchAction"}),
"NewWatchAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewWatchAction"}),
"NewUpdateSubresourceAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewUpdateSubresourceAction"}),
"NewRootUpdateSubresourceAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewRootUpdateSubresourceAction"}),
"NewRootPatchAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewRootPatchAction"}),
"NewPatchAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewPatchAction"}),
"NewRootPatchSubresourceAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewRootPatchSubresourceAction"}),
"NewPatchSubresourceAction": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "NewPatchSubresourceAction"}),
"ExtractFromListOptions": c.Universe.Function(types.Name{Package: pkgTestingCore, Name: "ExtractFromListOptions"}),
}
if g.version == "" {
m["DeleteOptions"] = c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/api", Name: "DeleteOptions"})
m["ListOptions"] = c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/api", Name: "ListOptions"})
} else {
m["DeleteOptions"] = c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/api/v1", Name: "DeleteOptions"})
m["ListOptions"] = c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/api/v1", Name: "ListOptions"})
}
m["GetOptions"] = c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/apis/meta/v1", Name: "GetOptions"})
noMethods := extractBoolTagOrDie("noMethods", t.SecondClosestCommentLines) == true
if namespaced {
sw.Do(structNamespaced, m)
} else {
sw.Do(structNonNamespaced, m)
}
if !noMethods {
sw.Do(resource, m)
sw.Do(createTemplate, m)
sw.Do(updateTemplate, m)
// Generate the UpdateStatus method if the type has a status
if genStatus(t) {
sw.Do(updateStatusTemplate, m)
}
sw.Do(deleteTemplate, m)
sw.Do(deleteCollectionTemplate, m)
sw.Do(getTemplate, m)
if hasObjectMeta(t) {
sw.Do(listUsingOptionsTemplate, m)
} else {
sw.Do(listTemplate, m)
}
sw.Do(watchTemplate, m)
sw.Do(patchTemplate, m)
}
return sw.Error()
}
示例8: Packages
// Packages makes the client package definition.
func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
boilerplate, err := arguments.LoadGoBoilerplate()
if err != nil {
glog.Fatalf("Failed loading boilerplate: %v", err)
}
boilerplate = append(boilerplate, []byte(generatedBy())...)
customArgs, ok := arguments.CustomArgs.(*CustomArgs)
if !ok {
glog.Fatalf("Wrong CustomArgs type: %T", arguments.CustomArgs)
}
var packageList generator.Packages
typesForGroupVersion := make(map[clientgentypes.GroupVersion][]*types.Type)
groupVersions := make(map[string]clientgentypes.GroupVersions)
for _, inputDir := range arguments.InputDirs {
p := context.Universe.Package(inputDir)
objectMeta, err := objectMetaForPackage(p)
if err != nil {
glog.Fatal(err)
}
if objectMeta == nil {
// no types in this package had genclient
continue
}
var gv clientgentypes.GroupVersion
if isInternal(objectMeta) {
lastSlash := strings.LastIndex(p.Path, "/")
if lastSlash == -1 {
glog.Fatalf("error constructing internal group version for package %q", p.Path)
}
gv.Group = clientgentypes.Group(p.Path[lastSlash+1:])
} else {
parts := strings.Split(p.Path, "/")
gv.Group = clientgentypes.Group(parts[len(parts)-2])
gv.Version = clientgentypes.Version(parts[len(parts)-1])
}
var typesToGenerate []*types.Type
for _, t := range p.Types {
// filter out types which dont have genclient=true.
if extractBoolTagOrDie("genclient", t.SecondClosestCommentLines) == false {
continue
}
// filter out types which have noMethods
if extractBoolTagOrDie("noMethods", t.SecondClosestCommentLines) == true {
continue
}
typesToGenerate = append(typesToGenerate, t)
if _, ok := typesForGroupVersion[gv]; !ok {
typesForGroupVersion[gv] = []*types.Type{}
}
typesForGroupVersion[gv] = append(typesForGroupVersion[gv], t)
}
if len(typesToGenerate) == 0 {
continue
}
icGroupName := namer.IC(gv.Group.NonEmpty())
groupVersionsEntry, ok := groupVersions[icGroupName]
if !ok {
groupVersionsEntry = clientgentypes.GroupVersions{
Group: gv.Group,
}
}
groupVersionsEntry.Versions = append(groupVersionsEntry.Versions, gv.Version)
groupVersions[icGroupName] = groupVersionsEntry
orderer := namer.Orderer{Namer: namer.NewPrivateNamer(0)}
typesToGenerate = orderer.OrderTypes(typesToGenerate)
packageList = append(packageList, versionPackage(arguments.OutputPackagePath, gv, boilerplate, typesToGenerate, customArgs.InternalClientSetPackage, customArgs.VersionedClientSetPackage, customArgs.ListersPackage))
}
packageList = append(packageList, factoryInterfacePackage(arguments.OutputPackagePath, boilerplate, customArgs.InternalClientSetPackage, customArgs.VersionedClientSetPackage, typesForGroupVersion))
packageList = append(packageList, factoryPackage(arguments.OutputPackagePath, boilerplate, groupVersions, customArgs.InternalClientSetPackage, customArgs.VersionedClientSetPackage, typesForGroupVersion))
for _, groupVersionsEntry := range groupVersions {
packageList = append(packageList, groupPackage(arguments.OutputPackagePath, groupVersionsEntry, boilerplate))
}
return packageList
}