mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 03:57:41 +00:00
Fix lint in code-generator/cmd/...
Later commits touch code around here, which triggers verify. This commit JUST fixes lint.
This commit is contained in:
parent
b68340e5b6
commit
01a1865934
@ -171,9 +171,5 @@ func requiresApplyConfiguration(t *types.Type) bool {
|
|||||||
hasJSONTaggedMembers = true
|
hasJSONTaggedMembers = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !hasJSONTaggedMembers {
|
return hasJSONTaggedMembers
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,9 @@ func (p *groupVersionsBuilder) update() error {
|
|||||||
|
|
||||||
versionPkg := types.PackageVersion{Package: path.Join(p.importBasePath, pth, gv.Group.NonEmpty(), gv.Version.String()), Version: gv.Version}
|
versionPkg := types.PackageVersion{Package: path.Join(p.importBasePath, pth, gv.Group.NonEmpty(), gv.Version.String()), Version: gv.Version}
|
||||||
if group, ok := seenGroups[gv.Group]; ok {
|
if group, ok := seenGroups[gv.Group]; ok {
|
||||||
seenGroups[gv.Group].Versions = append(group.Versions, versionPkg)
|
vers := group.Versions
|
||||||
|
vers = append(vers, versionPkg)
|
||||||
|
seenGroups[gv.Group].Versions = vers
|
||||||
} else {
|
} else {
|
||||||
seenGroups[gv.Group] = &types.GroupVersions{
|
seenGroups[gv.Group] = &types.GroupVersions{
|
||||||
PackageName: gv.Group.NonEmpty(),
|
PackageName: gv.Group.NonEmpty(),
|
||||||
|
@ -299,7 +299,9 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
|
|||||||
// TODO: Make the verbs in templates parametrized so the strings.Replace() is
|
// TODO: Make the verbs in templates parametrized so the strings.Replace() is
|
||||||
// not needed.
|
// not needed.
|
||||||
func adjustTemplate(name, verbType, template string) string {
|
func adjustTemplate(name, verbType, template string) string {
|
||||||
return strings.Replace(template, " "+strings.Title(verbType), " "+name, -1)
|
//nolint:staticcheck
|
||||||
|
// TODO: convert this to use golang.org/x/text/cases
|
||||||
|
return strings.ReplaceAll(template, " "+strings.Title(verbType), " "+name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// template for the struct that implements the type's interface
|
// template for the struct that implements the type's interface
|
||||||
|
@ -120,8 +120,12 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
|
|||||||
}
|
}
|
||||||
var updatedVerbtemplate string
|
var updatedVerbtemplate string
|
||||||
if _, exists := subresourceDefaultVerbTemplates[e.VerbType]; e.IsSubresource() && exists {
|
if _, exists := subresourceDefaultVerbTemplates[e.VerbType]; e.IsSubresource() && exists {
|
||||||
|
//nolint:staticcheck
|
||||||
|
// TODO: convert this to use golang.org/x/text/cases
|
||||||
updatedVerbtemplate = e.VerbName + "(" + strings.TrimPrefix(subresourceDefaultVerbTemplates[e.VerbType], strings.Title(e.VerbType)+"(")
|
updatedVerbtemplate = e.VerbName + "(" + strings.TrimPrefix(subresourceDefaultVerbTemplates[e.VerbType], strings.Title(e.VerbType)+"(")
|
||||||
} else {
|
} else {
|
||||||
|
//nolint:staticcheck
|
||||||
|
// TODO: convert this to use golang.org/x/text/cases
|
||||||
updatedVerbtemplate = e.VerbName + "(" + strings.TrimPrefix(defaultVerbTemplates[e.VerbType], strings.Title(e.VerbType)+"(")
|
updatedVerbtemplate = e.VerbName + "(" + strings.TrimPrefix(defaultVerbTemplates[e.VerbType], strings.Title(e.VerbType)+"(")
|
||||||
}
|
}
|
||||||
extendedMethod := extendedInterfaceMethod{
|
extendedMethod := extendedInterfaceMethod{
|
||||||
@ -345,7 +349,9 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
|
|||||||
// TODO: Make the verbs in templates parametrized so the strings.Replace() is
|
// TODO: Make the verbs in templates parametrized so the strings.Replace() is
|
||||||
// not needed.
|
// not needed.
|
||||||
func adjustTemplate(name, verbType, template string) string {
|
func adjustTemplate(name, verbType, template string) string {
|
||||||
return strings.Replace(template, " "+strings.Title(verbType), " "+name, -1)
|
//nolint:staticcheck
|
||||||
|
// TODO: convert this to use golang.org/x/text/cases
|
||||||
|
return strings.ReplaceAll(template, " "+strings.Title(verbType), " "+name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateInterface(defaultVerbTemplates map[string]string, tags util.Tags) string {
|
func generateInterface(defaultVerbTemplates map[string]string, tags util.Tags) string {
|
||||||
|
@ -116,6 +116,6 @@ func ToGroupInstallPackages(groups []GroupVersions, groupGoNames map[GroupVersio
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NormalizeGroupVersion calls normalizes the GroupVersion.
|
// NormalizeGroupVersion calls normalizes the GroupVersion.
|
||||||
//func NormalizeGroupVersion(gv GroupVersion) GroupVersion {
|
// func NormalizeGroupVersion(gv GroupVersion) GroupVersion {
|
||||||
// return GroupVersion{Group: gv.Group.NonEmpty(), Version: gv.Version, NonEmptyVersion: normalization.Version(gv.Version)}
|
// return GroupVersion{Group: gv.Group.NonEmpty(), Version: gv.Version, NonEmptyVersion: normalization.Version(gv.Version)}
|
||||||
//}
|
// }
|
||||||
|
@ -273,7 +273,8 @@ func GetTargets(context *generator.Context, arguments *args.GeneratorArgs) []gen
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make sure explicit peer-packages are added.
|
// Make sure explicit peer-packages are added.
|
||||||
peers := append(customArgs.BasePeerDirs, customArgs.ExtraPeerDirs...)
|
peers := customArgs.BasePeerDirs
|
||||||
|
peers = append(peers, customArgs.ExtraPeerDirs...)
|
||||||
if expanded, err := context.FindPackages(peers...); err != nil {
|
if expanded, err := context.FindPackages(peers...); err != nil {
|
||||||
klog.Fatalf("cannot find peer packages: %v", err)
|
klog.Fatalf("cannot find peer packages: %v", err)
|
||||||
} else {
|
} else {
|
||||||
@ -547,7 +548,8 @@ func (g *genConversion) convertibleOnlyWithinPackage(inType, outType *types.Type
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getExplicitFromTypes(t *types.Type) []types.Name {
|
func getExplicitFromTypes(t *types.Type) []types.Name {
|
||||||
comments := append(t.SecondClosestCommentLines, t.CommentLines...)
|
comments := t.SecondClosestCommentLines
|
||||||
|
comments = append(comments, t.CommentLines...)
|
||||||
paths := extractExplicitFromTag(comments)
|
paths := extractExplicitFromTag(comments)
|
||||||
result := []types.Name{}
|
result := []types.Name{}
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
@ -688,10 +690,7 @@ func (g *genConversion) Init(c *generator.Context, w io.Writer) error {
|
|||||||
}
|
}
|
||||||
// sort by name of the conversion function
|
// sort by name of the conversion function
|
||||||
sort.Slice(pairs, func(i, j int) bool {
|
sort.Slice(pairs, func(i, j int) bool {
|
||||||
if g.manualConversions[pairs[i]].Name.Name < g.manualConversions[pairs[j]].Name.Name {
|
return g.manualConversions[pairs[i]].Name.Name < g.manualConversions[pairs[j]].Name.Name
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
})
|
})
|
||||||
for _, pair := range pairs {
|
for _, pair := range pairs {
|
||||||
args := argsFromType(pair.inType, pair.outType).With("Scope", types.Ref(conversionPackagePath, "Scope")).With("fn", g.manualConversions[pair])
|
args := argsFromType(pair.inType, pair.outType).With("Scope", types.Ref(conversionPackagePath, "Scope")).With("fn", g.manualConversions[pair])
|
||||||
@ -725,7 +724,7 @@ func (g *genConversion) GenerateType(c *generator.Context, t *types.Type, w io.W
|
|||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case inType.Name.Package == "net/url" && inType.Name.Name == "Values":
|
case inType.Name.Package == "net/url" && inType.Name.Name == "Values":
|
||||||
g.generateFromUrlValues(inType, t, sw)
|
g.generateFromURLValues(inType, t, sw)
|
||||||
default:
|
default:
|
||||||
klog.Errorf("Not supported input type: %#v", inType.Name)
|
klog.Errorf("Not supported input type: %#v", inType.Name)
|
||||||
}
|
}
|
||||||
@ -1081,7 +1080,7 @@ func (g *genConversion) doUnknown(inType, outType *types.Type, sw *generator.Sni
|
|||||||
sw.Do("// FIXME: Type $.|raw$ is unsupported.\n", inType)
|
sw.Do("// FIXME: Type $.|raw$ is unsupported.\n", inType)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *genConversion) generateFromUrlValues(inType, outType *types.Type, sw *generator.SnippetWriter) {
|
func (g *genConversion) generateFromURLValues(inType, outType *types.Type, sw *generator.SnippetWriter) {
|
||||||
args := generator.Args{
|
args := generator.Args{
|
||||||
"inType": inType,
|
"inType": inType,
|
||||||
"outType": outType,
|
"outType": outType,
|
||||||
|
@ -258,7 +258,8 @@ func Run(g *Generator) {
|
|||||||
// Alternately, we could generate into a temp path and then move the
|
// Alternately, we could generate into a temp path and then move the
|
||||||
// resulting file back to the input dir, but that seems brittle in other
|
// resulting file back to the input dir, but that seems brittle in other
|
||||||
// ways.
|
// ways.
|
||||||
args := append(searchArgs, fmt.Sprintf("--gogo_out=%s", g.OutputDir))
|
args := searchArgs
|
||||||
|
args = append(args, fmt.Sprintf("--gogo_out=%s", g.OutputDir))
|
||||||
|
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
if len(g.Conditional) > 0 {
|
if len(g.Conditional) > 0 {
|
||||||
@ -391,9 +392,9 @@ func importOrder(deps map[string][]string) ([]string, error) {
|
|||||||
if len(remainingNodes) > 0 {
|
if len(remainingNodes) > 0 {
|
||||||
return nil, fmt.Errorf("cycle: remaining nodes: %#v, remaining edges: %#v", remainingNodes, graph)
|
return nil, fmt.Errorf("cycle: remaining nodes: %#v, remaining edges: %#v", remainingNodes, graph)
|
||||||
}
|
}
|
||||||
//for _, n := range sorted {
|
// for _, n := range sorted {
|
||||||
// fmt.Println("topological order", n)
|
// fmt.Println("topological order", n)
|
||||||
//}
|
// }
|
||||||
return sorted, nil
|
return sorted, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,7 +452,5 @@ func (o positionOrder) Less(i, j int) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (o positionOrder) Swap(i, j int) {
|
func (o positionOrder) Swap(i, j int) {
|
||||||
x := o.elements[i]
|
o.elements[i], o.elements[j] = o.elements[j], o.elements[i]
|
||||||
o.elements[i] = o.elements[j]
|
|
||||||
o.elements[j] = x
|
|
||||||
}
|
}
|
||||||
|
@ -229,9 +229,8 @@ func (p protobufLocator) GoTypeForName(name types.Name) *types.Type {
|
|||||||
|
|
||||||
// ProtoTypeFor locates a Protobuf type for the provided Go type (if possible).
|
// ProtoTypeFor locates a Protobuf type for the provided Go type (if possible).
|
||||||
func (p protobufLocator) ProtoTypeFor(t *types.Type) (*types.Type, error) {
|
func (p protobufLocator) ProtoTypeFor(t *types.Type) (*types.Type, error) {
|
||||||
switch {
|
|
||||||
// we've already converted the type, or it's a map
|
// we've already converted the type, or it's a map
|
||||||
case t.Kind == types.Protobuf || t.Kind == types.Map:
|
if t.Kind == types.Protobuf || t.Kind == types.Map {
|
||||||
p.tracker.AddType(t)
|
p.tracker.AddType(t)
|
||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
@ -559,11 +558,11 @@ func protobufTagToField(tag string, field *protoField, m types.Member, t *types.
|
|||||||
// protobuf:"bytes,3,opt,name=Id,customtype=github.com/gogo/protobuf/test.Uuid"
|
// protobuf:"bytes,3,opt,name=Id,customtype=github.com/gogo/protobuf/test.Uuid"
|
||||||
parts := strings.Split(tag, ",")
|
parts := strings.Split(tag, ",")
|
||||||
if len(parts) < 3 {
|
if len(parts) < 3 {
|
||||||
return fmt.Errorf("member %q of %q malformed 'protobuf' tag, not enough segments\n", m.Name, t.Name)
|
return fmt.Errorf("member %q of %q malformed 'protobuf' tag, not enough segments", m.Name, t.Name)
|
||||||
}
|
}
|
||||||
protoTag, err := strconv.Atoi(parts[1])
|
protoTag, err := strconv.Atoi(parts[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("member %q of %q malformed 'protobuf' tag, field ID is %q which is not an integer: %v\n", m.Name, t.Name, parts[1], err)
|
return fmt.Errorf("member %q of %q malformed 'protobuf' tag, field ID is %q which is not an integer: %w", m.Name, t.Name, parts[1], err)
|
||||||
}
|
}
|
||||||
field.Tag = protoTag
|
field.Tag = protoTag
|
||||||
|
|
||||||
@ -584,7 +583,7 @@ func protobufTagToField(tag string, field *protoField, m types.Member, t *types.
|
|||||||
name = types.Name{
|
name = types.Name{
|
||||||
Name: parts[0][last+1:],
|
Name: parts[0][last+1:],
|
||||||
Package: prefix,
|
Package: prefix,
|
||||||
Path: strings.Replace(prefix, ".", "/", -1),
|
Path: strings.ReplaceAll(prefix, ".", "/"),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
name = types.Name{
|
name = types.Name{
|
||||||
@ -603,7 +602,7 @@ func protobufTagToField(tag string, field *protoField, m types.Member, t *types.
|
|||||||
for i, extra := range parts[3:] {
|
for i, extra := range parts[3:] {
|
||||||
parts := strings.SplitN(extra, "=", 2)
|
parts := strings.SplitN(extra, "=", 2)
|
||||||
if len(parts) != 2 {
|
if len(parts) != 2 {
|
||||||
return fmt.Errorf("member %q of %q malformed 'protobuf' tag, tag %d should be key=value, got %q\n", m.Name, t.Name, i+4, extra)
|
return fmt.Errorf("member %q of %q malformed 'protobuf' tag, tag %d should be key=value, got %q", m.Name, t.Name, i+4, extra)
|
||||||
}
|
}
|
||||||
switch parts[0] {
|
switch parts[0] {
|
||||||
case "name":
|
case "name":
|
||||||
|
@ -87,8 +87,8 @@ func (n *protobufNamer) GoNameToProtoName(name types.Name) types.Name {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func protoSafePackage(name string) string {
|
func protoSafePackage(name string) string {
|
||||||
pkg := strings.Replace(name, "/", ".", -1)
|
pkg := strings.ReplaceAll(name, "/", ".")
|
||||||
return strings.Replace(pkg, "-", "_", -1)
|
return strings.ReplaceAll(pkg, "-", "_")
|
||||||
}
|
}
|
||||||
|
|
||||||
type typeNameSet map[types.Name]*protobufPackage
|
type typeNameSet map[types.Name]*protobufPackage
|
||||||
|
@ -111,8 +111,7 @@ func RewriteGeneratedGogoProtobufFile(name string, extractFn ExtractFunc, option
|
|||||||
// TODO: move into upstream gogo-protobuf once https://github.com/gogo/protobuf/issues/181
|
// TODO: move into upstream gogo-protobuf once https://github.com/gogo/protobuf/issues/181
|
||||||
// has agreement
|
// has agreement
|
||||||
func rewriteOptionalMethods(decl ast.Decl, isOptional OptionalFunc) {
|
func rewriteOptionalMethods(decl ast.Decl, isOptional OptionalFunc) {
|
||||||
switch t := decl.(type) {
|
if t, ok := decl.(*ast.FuncDecl); ok {
|
||||||
case *ast.FuncDecl:
|
|
||||||
ident, ptr, ok := receiver(t)
|
ident, ptr, ok := receiver(t)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
@ -150,8 +149,7 @@ type optionalAssignmentVisitor struct {
|
|||||||
// Visit walks the provided node, transforming field initializations of the form
|
// Visit walks the provided node, transforming field initializations of the form
|
||||||
// m.Field = &OptionalType{} -> m.Field = OptionalType{}
|
// m.Field = &OptionalType{} -> m.Field = OptionalType{}
|
||||||
func (v optionalAssignmentVisitor) Visit(n ast.Node) ast.Visitor {
|
func (v optionalAssignmentVisitor) Visit(n ast.Node) ast.Visitor {
|
||||||
switch t := n.(type) {
|
if t, ok := n.(*ast.AssignStmt); ok {
|
||||||
case *ast.AssignStmt:
|
|
||||||
if len(t.Lhs) == 1 && len(t.Rhs) == 1 {
|
if len(t.Lhs) == 1 && len(t.Rhs) == 1 {
|
||||||
if !isFieldSelector(t.Lhs[0], "m", "") {
|
if !isFieldSelector(t.Lhs[0], "m", "") {
|
||||||
return nil
|
return nil
|
||||||
@ -195,13 +193,11 @@ func (v *optionalItemsVisitor) Visit(n ast.Node) ast.Visitor {
|
|||||||
t.Lhs[0] = &ast.StarExpr{X: &ast.Ident{Name: "m"}}
|
t.Lhs[0] = &ast.StarExpr{X: &ast.Ident{Name: "m"}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch rhs := t.Rhs[0].(type) {
|
if rhs, ok := t.Rhs[0].(*ast.CallExpr); ok {
|
||||||
case *ast.CallExpr:
|
|
||||||
if ident, ok := rhs.Fun.(*ast.Ident); ok && ident.Name == "append" {
|
if ident, ok := rhs.Fun.(*ast.Ident); ok && ident.Name == "append" {
|
||||||
ast.Walk(v, rhs)
|
ast.Walk(v, rhs)
|
||||||
if len(rhs.Args) > 0 {
|
if len(rhs.Args) > 0 {
|
||||||
switch arg := rhs.Args[0].(type) {
|
if arg, ok := rhs.Args[0].(*ast.Ident); ok {
|
||||||
case *ast.Ident:
|
|
||||||
if arg.Name == "m" {
|
if arg.Name == "m" {
|
||||||
rhs.Args[0] = &ast.StarExpr{X: &ast.Ident{Name: "m"}}
|
rhs.Args[0] = &ast.StarExpr{X: &ast.Ident{Name: "m"}}
|
||||||
}
|
}
|
||||||
@ -212,8 +208,7 @@ func (v *optionalItemsVisitor) Visit(n ast.Node) ast.Visitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case *ast.IfStmt:
|
case *ast.IfStmt:
|
||||||
switch cond := t.Cond.(type) {
|
if cond, ok := t.Cond.(*ast.BinaryExpr); ok {
|
||||||
case *ast.BinaryExpr:
|
|
||||||
if cond.Op == token.EQL {
|
if cond.Op == token.EQL {
|
||||||
if isFieldSelector(cond.X, "m", "Items") && isIdent(cond.Y, "nil") {
|
if isFieldSelector(cond.X, "m", "Items") && isIdent(cond.Y, "nil") {
|
||||||
cond.X = &ast.StarExpr{X: &ast.Ident{Name: "m"}}
|
cond.X = &ast.StarExpr{X: &ast.Ident{Name: "m"}}
|
||||||
@ -225,8 +220,7 @@ func (v *optionalItemsVisitor) Visit(n ast.Node) ast.Visitor {
|
|||||||
// if err := m[len(m.Items)-1].Unmarshal(data[iNdEx:postIndex]); err != nil {
|
// if err := m[len(m.Items)-1].Unmarshal(data[iNdEx:postIndex]); err != nil {
|
||||||
// return err
|
// return err
|
||||||
// }
|
// }
|
||||||
switch s := t.Init.(type) {
|
if s, ok := t.Init.(*ast.AssignStmt); ok {
|
||||||
case *ast.AssignStmt:
|
|
||||||
if call, ok := s.Rhs[0].(*ast.CallExpr); ok {
|
if call, ok := s.Rhs[0].(*ast.CallExpr); ok {
|
||||||
if sel, ok := call.Fun.(*ast.SelectorExpr); ok {
|
if sel, ok := call.Fun.(*ast.SelectorExpr); ok {
|
||||||
if x, ok := sel.X.(*ast.IndexExpr); ok {
|
if x, ok := sel.X.(*ast.IndexExpr); ok {
|
||||||
@ -302,15 +296,13 @@ func receiver(f *ast.FuncDecl) (ident *ast.Ident, pointer bool, ok bool) {
|
|||||||
// dropExistingTypeDeclarations removes any type declaration for which extractFn returns true. The function
|
// dropExistingTypeDeclarations removes any type declaration for which extractFn returns true. The function
|
||||||
// returns true if the entire declaration should be dropped.
|
// returns true if the entire declaration should be dropped.
|
||||||
func dropExistingTypeDeclarations(decl ast.Decl, extractFn ExtractFunc) bool {
|
func dropExistingTypeDeclarations(decl ast.Decl, extractFn ExtractFunc) bool {
|
||||||
switch t := decl.(type) {
|
if t, ok := decl.(*ast.GenDecl); ok {
|
||||||
case *ast.GenDecl:
|
|
||||||
if t.Tok != token.TYPE {
|
if t.Tok != token.TYPE {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
specs := []ast.Spec{}
|
specs := []ast.Spec{}
|
||||||
for _, s := range t.Specs {
|
for _, s := range t.Specs {
|
||||||
switch spec := s.(type) {
|
if spec, ok := s.(*ast.TypeSpec); ok {
|
||||||
case *ast.TypeSpec:
|
|
||||||
if extractFn(spec) {
|
if extractFn(spec) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -329,15 +321,13 @@ func dropExistingTypeDeclarations(decl ast.Decl, extractFn ExtractFunc) bool {
|
|||||||
// to prevent generation from being able to define side-effects. The function returns true
|
// to prevent generation from being able to define side-effects. The function returns true
|
||||||
// if the entire declaration should be dropped.
|
// if the entire declaration should be dropped.
|
||||||
func dropEmptyImportDeclarations(decl ast.Decl) bool {
|
func dropEmptyImportDeclarations(decl ast.Decl) bool {
|
||||||
switch t := decl.(type) {
|
if t, ok := decl.(*ast.GenDecl); ok {
|
||||||
case *ast.GenDecl:
|
|
||||||
if t.Tok != token.IMPORT {
|
if t.Tok != token.IMPORT {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
specs := []ast.Spec{}
|
specs := []ast.Spec{}
|
||||||
for _, s := range t.Specs {
|
for _, s := range t.Specs {
|
||||||
switch spec := s.(type) {
|
if spec, ok := s.(*ast.ImportSpec); ok {
|
||||||
case *ast.ImportSpec:
|
|
||||||
if spec.Name != nil && spec.Name.Name == "_" {
|
if spec.Name != nil && spec.Name.Name == "_" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -107,10 +107,8 @@ func TestProtoParser(t *testing.T) {
|
|||||||
if !test.err {
|
if !test.err {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%s: unexpected error %s", test.expr, err)
|
t.Errorf("%s: unexpected error %s", test.expr, err)
|
||||||
} else {
|
} else if actual != ident.Name {
|
||||||
if actual != ident.Name {
|
t.Errorf("%s: expected %s, got %s", test.expr, ident.Name, actual)
|
||||||
t.Errorf("%s: expected %s, got %s", test.expr, ident.Name, actual)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -237,25 +237,25 @@ func (g *listerGenerator) GenerateType(c *generator.Context, t *types.Type, w io
|
|||||||
}
|
}
|
||||||
|
|
||||||
if tags.NonNamespaced {
|
if tags.NonNamespaced {
|
||||||
sw.Do(typeListerInterface_NonNamespaced, m)
|
sw.Do(typeListerInterfaceNonNamespaced, m)
|
||||||
} else {
|
} else {
|
||||||
sw.Do(typeListerInterface, m)
|
sw.Do(typeListerInterface, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
sw.Do(typeListerStruct, m)
|
sw.Do(typeListerStruct, m)
|
||||||
sw.Do(typeListerConstructor, m)
|
sw.Do(typeListerConstructor, m)
|
||||||
sw.Do(typeLister_List, m)
|
sw.Do(typeListerList, m)
|
||||||
|
|
||||||
if tags.NonNamespaced {
|
if tags.NonNamespaced {
|
||||||
sw.Do(typeLister_NonNamespacedGet, m)
|
sw.Do(typeListerNonNamespacedGet, m)
|
||||||
return sw.Error()
|
return sw.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
sw.Do(typeLister_NamespaceLister, m)
|
sw.Do(typeListerNamespaceLister, m)
|
||||||
sw.Do(namespaceListerInterface, m)
|
sw.Do(namespaceListerInterface, m)
|
||||||
sw.Do(namespaceListerStruct, m)
|
sw.Do(namespaceListerStruct, m)
|
||||||
sw.Do(namespaceLister_List, m)
|
sw.Do(namespaceListerList, m)
|
||||||
sw.Do(namespaceLister_Get, m)
|
sw.Do(namespaceListerGet, m)
|
||||||
|
|
||||||
return sw.Error()
|
return sw.Error()
|
||||||
}
|
}
|
||||||
@ -273,7 +273,7 @@ type $.type|public$Lister interface {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
var typeListerInterface_NonNamespaced = `
|
var typeListerInterfaceNonNamespaced = `
|
||||||
// $.type|public$Lister helps list $.type|publicPlural$.
|
// $.type|public$Lister helps list $.type|publicPlural$.
|
||||||
// All objects returned here must be treated as read-only.
|
// All objects returned here must be treated as read-only.
|
||||||
type $.type|public$Lister interface {
|
type $.type|public$Lister interface {
|
||||||
@ -301,7 +301,7 @@ func New$.type|public$Lister(indexer cache.Indexer) $.type|public$Lister {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
var typeLister_List = `
|
var typeListerList = `
|
||||||
// List lists all $.type|publicPlural$ in the indexer.
|
// List lists all $.type|publicPlural$ in the indexer.
|
||||||
func (s *$.type|private$Lister) List(selector labels.Selector) (ret []*$.type|raw$, err error) {
|
func (s *$.type|private$Lister) List(selector labels.Selector) (ret []*$.type|raw$, err error) {
|
||||||
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
|
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
|
||||||
@ -311,14 +311,14 @@ func (s *$.type|private$Lister) List(selector labels.Selector) (ret []*$.type|ra
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
var typeLister_NamespaceLister = `
|
var typeListerNamespaceLister = `
|
||||||
// $.type|publicPlural$ returns an object that can list and get $.type|publicPlural$.
|
// $.type|publicPlural$ returns an object that can list and get $.type|publicPlural$.
|
||||||
func (s *$.type|private$Lister) $.type|publicPlural$(namespace string) $.type|public$NamespaceLister {
|
func (s *$.type|private$Lister) $.type|publicPlural$(namespace string) $.type|public$NamespaceLister {
|
||||||
return $.type|private$NamespaceLister{indexer: s.indexer, namespace: namespace}
|
return $.type|private$NamespaceLister{indexer: s.indexer, namespace: namespace}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
var typeLister_NonNamespacedGet = `
|
var typeListerNonNamespacedGet = `
|
||||||
// Get retrieves the $.type|public$ from the index for a given name.
|
// Get retrieves the $.type|public$ from the index for a given name.
|
||||||
func (s *$.type|private$Lister) Get(name string) (*$.type|raw$, error) {
|
func (s *$.type|private$Lister) Get(name string) (*$.type|raw$, error) {
|
||||||
obj, exists, err := s.indexer.GetByKey(name)
|
obj, exists, err := s.indexer.GetByKey(name)
|
||||||
@ -355,7 +355,7 @@ type $.type|private$NamespaceLister struct {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
var namespaceLister_List = `
|
var namespaceListerList = `
|
||||||
// List lists all $.type|publicPlural$ in the indexer for a given namespace.
|
// List lists all $.type|publicPlural$ in the indexer for a given namespace.
|
||||||
func (s $.type|private$NamespaceLister) List(selector labels.Selector) (ret []*$.type|raw$, err error) {
|
func (s $.type|private$NamespaceLister) List(selector labels.Selector) (ret []*$.type|raw$, err error) {
|
||||||
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
|
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
|
||||||
@ -365,7 +365,7 @@ func (s $.type|private$NamespaceLister) List(selector labels.Selector) (ret []*$
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
var namespaceLister_Get = `
|
var namespaceListerGet = `
|
||||||
// Get retrieves the $.type|public$ from the indexer for a given namespace and name.
|
// Get retrieves the $.type|public$ from the indexer for a given namespace and name.
|
||||||
func (s $.type|private$NamespaceLister) Get(name string) (*$.type|raw$, error) {
|
func (s $.type|private$NamespaceLister) Get(name string) (*$.type|raw$, error) {
|
||||||
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
|
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
|
||||||
|
@ -109,7 +109,7 @@ func extractReplacementTag(t *types.Type) (group, version, kind string, hasRepla
|
|||||||
}
|
}
|
||||||
// If there are multiple values, abort.
|
// If there are multiple values, abort.
|
||||||
if len(tagVals) > 1 {
|
if len(tagVals) > 1 {
|
||||||
return "", "", "", false, fmt.Errorf("Found %d %s tags: %q", len(tagVals), replacementTagName, tagVals)
|
return "", "", "", false, fmt.Errorf("found %d %s tags: %q", len(tagVals), replacementTagName, tagVals)
|
||||||
}
|
}
|
||||||
tagValue := tagVals[0]
|
tagValue := tagVals[0]
|
||||||
parts := strings.Split(tagValue, ",")
|
parts := strings.Split(tagValue, ",")
|
||||||
|
Loading…
Reference in New Issue
Block a user