本文整理汇总了Golang中k8s/io/gengo/generator.NewSnippetWriter函数的典型用法代码示例。如果您正苦于以下问题:Golang NewSnippetWriter函数的具体用法?Golang NewSnippetWriter怎么用?Golang NewSnippetWriter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewSnippetWriter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GenerateType
func (g *genDefaulter) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
if _, ok := g.newDefaulters[t]; !ok {
return nil
}
glog.V(5).Infof("generating for type %v", t)
callTree := buildCallTreeForType(t, true, g.existingDefaulters, g.newDefaulters)
if callTree == nil {
glog.V(5).Infof(" no defaulters defined")
return nil
}
i := 0
callTree.VisitInOrder(func(ancestors []*callNode, current *callNode) {
if len(current.call) == 0 {
return
}
path := callPath(append(ancestors, current))
glog.V(5).Infof(" %d: %s", i, path)
i++
})
sw := generator.NewSnippetWriter(w, c, "$", "$")
g.generateDefaulter(t, callTree, sw)
return sw.Error()
}
示例2: GenerateType
func (g *factoryGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "{{", "}}")
glog.V(5).Infof("processing type %v", t)
gvInterfaces := make(map[string]*types.Type)
gvNewFuncs := make(map[string]*types.Type)
for groupName := range g.groupVersions {
gvInterfaces[groupName] = c.Universe.Type(types.Name{Package: packageForGroup(g.outputPackage, g.groupVersions[groupName].Group), Name: "Interface"})
gvNewFuncs[groupName] = c.Universe.Function(types.Name{Package: packageForGroup(g.outputPackage, g.groupVersions[groupName].Group), Name: "New"})
}
m := map[string]interface{}{
"cacheSharedIndexInformer": c.Universe.Type(cacheSharedIndexInformer),
"groupVersions": g.groupVersions,
"gvInterfaces": gvInterfaces,
"gvNewFuncs": gvNewFuncs,
"interfacesNewInternalInformerFunc": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "NewInternalInformerFunc"}),
"interfacesNewVersionedInformerFunc": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "NewVersionedInformerFunc"}),
"informerFactoryInterface": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "SharedInformerFactory"}),
"internalClientSetInterface": c.Universe.Type(types.Name{Package: g.internalClientSetPackage, Name: "Interface"}),
"reflectType": c.Universe.Type(reflectType),
"runtimeObject": c.Universe.Type(runtimeObject),
"syncMutex": c.Universe.Type(syncMutex),
"timeDuration": c.Universe.Type(timeDuration),
"versionedClientSetInterface": c.Universe.Type(types.Name{Package: g.versionedClientSetPackage, Name: "Interface"}),
}
sw.Do(sharedInformerFactoryStruct, m)
sw.Do(sharedInformerFactoryInterface, m)
return sw.Error()
}
示例3: GenerateType
func (g *listerGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "$", "$")
glog.V(5).Infof("processing type %v", t)
m := map[string]interface{}{
"Resource": c.Universe.Function(types.Name{Package: g.internalGVPkg, Name: "Resource"}),
"type": t,
"objectMeta": g.objectMeta,
}
namespaced := !extractBoolTagOrDie("nonNamespaced", t.SecondClosestCommentLines)
if namespaced {
sw.Do(typeListerInterface, m)
} else {
sw.Do(typeListerInterface_NonNamespaced, m)
}
sw.Do(typeListerStruct, m)
sw.Do(typeListerConstructor, m)
sw.Do(typeLister_List, m)
if namespaced {
sw.Do(typeLister_NamespaceLister, m)
sw.Do(namespaceListerInterface, m)
sw.Do(namespaceListerStruct, m)
sw.Do(namespaceLister_List, m)
sw.Do(namespaceLister_Get, m)
} else {
sw.Do(typeLister_NonNamespacedGet, m)
}
return sw.Error()
}
示例4: 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()
}
示例5: Init
func (g *genDeepCopy) Init(c *generator.Context, w io.Writer) error {
cloner := c.Universe.Type(types.Name{Package: conversionPackagePath, Name: "Cloner"})
g.imports.AddType(cloner)
if !g.registerTypes {
// TODO: We should come up with a solution to register all generated
// deep-copy functions. However, for now, to avoid import cycles
// we register only those explicitly requested.
return nil
}
glog.V(5).Infof("registering types in pkg %q", g.targetPackage)
sw := generator.NewSnippetWriter(w, c, "$", "$")
sw.Do("func init() {\n", nil)
sw.Do("SchemeBuilder.Register(RegisterDeepCopies)\n", nil)
sw.Do("}\n\n", nil)
scheme := c.Universe.Type(types.Name{Package: runtimePackagePath, Name: "Scheme"})
schemePtr := &types.Type{
Kind: types.Pointer,
Elem: scheme,
}
sw.Do("// RegisterDeepCopies adds deep-copy functions to the given scheme. Public\n", nil)
sw.Do("// to allow building arbitrary schemes.\n", nil)
sw.Do("func RegisterDeepCopies(scheme $.|raw$) error {\n", schemePtr)
sw.Do("return scheme.AddGeneratedDeepCopyFuncs(\n", nil)
for _, t := range g.typesForInit {
args := argsFromType(t).
With("typeof", c.Universe.Package("reflect").Function("TypeOf"))
sw.Do("conversion.GeneratedDeepCopyFunc{Fn: $.type|dcFnName$, InType: $.typeof|raw$(&$.type|raw${})},\n", args)
}
sw.Do(")\n", nil)
sw.Do("}\n\n", nil)
return sw.Error()
}
示例6: GenerateType
// GenerateType makes the body of a file implementing a set for type t.
func (g *genProtoIDL) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "$", "$")
b := bodyGen{
locator: &protobufLocator{
namer: c.Namers["proto"].(ProtobufFromGoNamer),
tracker: g.imports,
universe: c.Universe,
localGoPackage: g.localGoPackage.Package,
},
localPackage: g.localPackage,
omitGogo: g.omitGogo,
omitFieldTypes: g.omitFieldTypes,
t: t,
}
switch t.Kind {
case types.Alias:
return b.doAlias(sw)
case types.Struct:
return b.doStruct(sw)
default:
return b.unknown(sw)
}
}
示例7: 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()
}
示例8: 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()
}
示例9: GenerateType
func (g *genConversion) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
glog.V(5).Infof("generating for type %v", t)
peerType := getPeerTypeFor(c, t, g.peerPackages)
sw := generator.NewSnippetWriter(w, c, "$", "$")
g.generateConversion(t, peerType, sw)
g.generateConversion(peerType, t, sw)
return sw.Error()
}
示例10: GenerateType
// GenerateType makes the body of a file implementing a set for type t.
func (g *genSet) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "$", "$")
sw.Do(setCode, g.args(t))
sw.Do("func less$.type|public$(lhs, rhs $.type|raw$) bool {\n", g.args(t))
g.lessBody(sw, t)
sw.Do("}\n", g.args(t))
return sw.Error()
}
示例11: GenerateType
func (g *genExpansion) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "$", "$")
for _, t := range g.types {
if _, err := os.Stat(filepath.Join(g.groupPath, strings.ToLower(t.Name.Name+"_expansion.go"))); os.IsNotExist(err) {
sw.Do(expansionInterfaceTemplate, t)
}
}
return sw.Error()
}
示例12: GenerateType
func (g *openAPIGen) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
glog.V(5).Infof("generating for type %v", t)
sw := generator.NewSnippetWriter(w, c, "$", "$")
err := newOpenAPITypeWriter(sw).generate(t)
if err != nil {
return err
}
return sw.Error()
}
示例13: Init
func (g *genDeepCopy) Init(c *generator.Context, w io.Writer) error {
cloner := c.Universe.Type(types.Name{Package: conversionPackagePath, Name: "Cloner"})
g.imports.AddType(cloner)
if !g.registerTypes {
sw := generator.NewSnippetWriter(w, c, "$", "$")
sw.Do("// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.\n", nil)
sw.Do("func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc{\n", nil)
sw.Do("return []conversion.GeneratedDeepCopyFunc{\n", nil)
for _, t := range g.typesForInit {
args := argsFromType(t).
With("typeof", c.Universe.Package("reflect").Function("TypeOf"))
sw.Do("{Fn: $.type|dcFnName$, InType: $.typeof|raw$(&$.type|raw${})},\n", args)
}
sw.Do("}\n", nil)
sw.Do("}\n\n", nil)
return sw.Error()
}
glog.V(5).Infof("Registering types in pkg %q", g.targetPackage)
sw := generator.NewSnippetWriter(w, c, "$", "$")
sw.Do("func init() {\n", nil)
sw.Do("SchemeBuilder.Register(RegisterDeepCopies)\n", nil)
sw.Do("}\n\n", nil)
scheme := c.Universe.Type(types.Name{Package: runtimePackagePath, Name: "Scheme"})
schemePtr := &types.Type{
Kind: types.Pointer,
Elem: scheme,
}
sw.Do("// RegisterDeepCopies adds deep-copy functions to the given scheme. Public\n", nil)
sw.Do("// to allow building arbitrary schemes.\n", nil)
sw.Do("func RegisterDeepCopies(scheme $.|raw$) error {\n", schemePtr)
sw.Do("return scheme.AddGeneratedDeepCopyFuncs(\n", nil)
for _, t := range g.typesForInit {
args := argsFromType(t).
With("typeof", c.Universe.Package("reflect").Function("TypeOf"))
sw.Do("conversion.GeneratedDeepCopyFunc{Fn: $.type|dcFnName$, InType: $.typeof|raw$(&$.type|raw${})},\n", args)
}
sw.Do(")\n", nil)
sw.Do("}\n\n", nil)
return sw.Error()
}
示例14: GenerateType
func (g *versionInterfaceGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "$", "$")
m := map[string]interface{}{
"interfacesSharedInformerFactory": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "SharedInformerFactory"}),
"types": g.types,
}
sw.Do(versionTemplate, m)
return sw.Error()
}
示例15: GenerateType
func (g *expansionGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
sw := generator.NewSnippetWriter(w, c, "$", "$")
for _, t := range g.types {
if _, err := os.Stat(filepath.Join(g.packagePath, strings.ToLower(t.Name.Name+"_expansion.go"))); os.IsNotExist(err) {
sw.Do(expansionInterfaceTemplate, t)
namespaced := !extractBoolTagOrDie("nonNamespaced", t.SecondClosestCommentLines)
if namespaced {
sw.Do(namespacedExpansionInterfaceTemplate, t)
}
}
}
return sw.Error()
}