func (p *plugin) Generate(file *generator.FileDescriptor) { for _, msg := range file.Messages() { for _, os := range overwriters { possible := true for _, overwriter := range os { if overwriter(file.FileDescriptorProto, msg.DescriptorProto) { possible = false } } if possible { p.checkOverwrite(msg, os) } } p.checkNameSpace(msg) for _, field := range msg.GetField() { if gogoproto.IsEmbed(field) && gogoproto.IsCustomName(field) { fmt.Fprintf(os.Stderr, "ERROR: field %v with custom name %v cannot be embedded", *field.Name, gogoproto.GetCustomName(field)) os.Exit(1) } } p.checkRepeated(msg) } for _, e := range file.GetExtension() { if gogoproto.IsEmbed(e) { fmt.Fprintf(os.Stderr, "ERROR: extended field %v cannot be embedded", generator.CamelCase(*e.Name)) os.Exit(1) } } }
func (p *plugin) Generate(file *generator.FileDescriptor) { for _, msg := range file.Messages() { getters := gogoproto.HasGoGetters(file.FileDescriptorProto, msg.DescriptorProto) face := gogoproto.IsFace(file.FileDescriptorProto, msg.DescriptorProto) for _, field := range msg.GetField() { if len(field.GetDefaultValue()) > 0 { if !getters { fmt.Fprintf(os.Stderr, "ERROR: field %v.%v cannot have a default value and not have a getter method", generator.CamelCase(*msg.Name), generator.CamelCase(*field.Name)) os.Exit(1) } if face { fmt.Fprintf(os.Stderr, "ERROR: field %v.%v cannot have a default value be in a face", generator.CamelCase(*msg.Name), generator.CamelCase(*field.Name)) os.Exit(1) } } if gogoproto.IsNullable(field) { continue } if len(field.GetDefaultValue()) > 0 { fmt.Fprintf(os.Stderr, "ERROR: field %v.%v cannot be nullable and have a default value", generator.CamelCase(*msg.Name), generator.CamelCase(*field.Name)) os.Exit(1) } if !field.IsEnum() { continue } enum := p.ObjectNamed(field.GetTypeName()).(*generator.EnumDescriptor) if len(enum.Value) == 0 || enum.Value[0].GetNumber() != 0 { fmt.Fprintf(os.Stderr, "ERROR: field %v.%v cannot be nullable and be an enum type %v which does not start with zero", generator.CamelCase(*msg.Name), generator.CamelCase(*field.Name), enum.GetName()) os.Exit(1) } } } for _, e := range file.GetExtension() { if !gogoproto.IsNullable(e) { fmt.Fprintf(os.Stderr, "ERROR: extended field %v cannot be nullable", generator.CamelCase(e.GetName()), generator.CamelCase(*e.Name)) os.Exit(1) } } }