func main() { req := command.Read() p := gostring.NewGoString() p.Overwrite() resp := command.GeneratePlugin(req, p, "_gostring.gen.go") command.Write(resp) }
func main() { req := command.Read() files := req.GetProtoFile() files = vanity.FilterFiles(files, vanity.NotGoogleProtobufDescriptorProto) vanity.ForEachFile(files, vanity.TurnOnMarshalerAll) vanity.ForEachFile(files, vanity.TurnOnSizerAll) vanity.ForEachFile(files, vanity.TurnOnUnmarshalerAll) vanity.ForEachFile(files, vanity.TurnOffGoEnumPrefixAll) vanity.ForEachFile(files, vanity.TurnOffGoEnumStringerAll) vanity.ForEachFile(files, vanity.TurnOnEnumStringerAll) vanity.ForEachFile(files, vanity.TurnOnEqualAll) vanity.ForEachFile(files, vanity.TurnOnGoStringAll) vanity.ForEachFile(files, vanity.TurnOffGoStringerAll) for _, file := range files { if strings.HasSuffix(file.GetName(), "timestamp.proto") || strings.HasSuffix(file.GetName(), "duration.proto") { continue } vanity.TurnOnStringerAll(file) vanity.TurnOnPopulateAll(file) } resp := command.Generate(req) command.Write(resp) }
func main() { req := command.Read() files := req.GetProtoFile() files = vanity.FilterFiles(files, vanity.NotInPackageGoogleProtobuf) vanity.ForEachFile(files, vanity.TurnOnPopulateAll) vanity.ForEachFile(files, vanity.TurnOnGoStringAll) vanity.ForEachFile(files, vanity.TurnOnDescriptionAll) resp := command.Generate(req) msgs := []string{} for _, file := range files { if file.GetPackage() == "fuzztests" { for _, message := range file.GetMessageType() { msgs = append(msgs, "NewPopulated"+message.GetName()) } } } content := ` // Code generated by protoc-gen-gogopop. // DO NOT EDIT! package fuzztests var popFuncs = []interface{}{ ` + strings.Join(msgs, ",\n") + `, }` newFile := &plugin.CodeGeneratorResponse_File{ Name: proto.String("./pop.gen.go"), Content: proto.String(content), } resp.File = append(resp.File, newFile) command.Write(resp) }
func main() { req := command.Read() files := req.GetProtoFile() vanity.ForEachFile(files, vanity.TurnOnMarshalerAll) vanity.ForEachFile(files, vanity.TurnOnSizerAll) vanity.ForEachFile(files, vanity.TurnOnUnmarshalerAll) resp := command.Generate(req) command.Write(resp) }
func main() { req := command.Read() files := req.GetProtoFile() files = vanity.FilterFiles(files, vanity.NotInPackageGoogleProtobuf) vanity.ForEachFile(files, vanity.TurnOnMarshalerAll) vanity.ForEachFile(files, vanity.TurnOnSizerAll) vanity.ForEachFile(files, vanity.TurnOnUnmarshalerAll) resp := command.Generate(req) command.Write(resp) }
func main() { req := command.Read() files := req.GetProtoFile() files = vanity.FilterFiles(files, vanity.NotInPackageGoogleProtobuf) vanity.ForEachFile(files, vanity.TurnOnMarshalerAll) vanity.ForEachFile(files, vanity.TurnOnSizerAll) vanity.ForEachFile(files, vanity.TurnOnUnmarshalerAll) vanity.ForEachFieldInFilesExcludingExtensions(vanity.OnlyProto2(files), vanity.TurnOffNullableForNativeTypesWithoutDefaultsOnly) vanity.ForEachFile(files, vanity.TurnOffGoUnrecognizedAll) resp := command.Generate(req) command.Write(resp) }
func main() { req := command.Read() files := req.GetProtoFile() vanity.ForEachFile(files, vanity.TurnOnMarshalerAll) vanity.ForEachFile(files, vanity.TurnOnSizerAll) vanity.ForEachFile(files, vanity.TurnOnUnmarshalerAll) vanity.ForEachFieldInFiles(files, vanity.TurnOffNullableForNativeTypesOnly) vanity.ForEachFile(files, vanity.TurnOffGoGettersAll) vanity.ForEachFile(files, vanity.TurnOffGoUnrecognizedAll) resp := command.Generate(req) command.Write(resp) }
func main() { req := command.Read() files := req.GetProtoFile() // Forced (to prevent mistake) vanity.ForEachFile(files, vanity.TurnOffGogoImport) // Default stuffs. vanity.ForEachFile(files, vanity.TurnOnSizerAll) // 'Marshal' needs this. vanity.ForEachFile(files, vanity.TurnOnUnmarshalerAll) vanity.ForEachFile(files, vanity.TurnOnMarshalerAll) // Apply custom fixes. vanity.ForEachFieldInFilesExcludingExtensions(files, fixFieldName) // vanity.ForEachFieldInFilesExcludingExtensions(files, fixNumericJSONTag) resp := command.Generate(req) command.Write(resp) }
func main() { req := command.Read() files := req.GetProtoFile() files = vanity.FilterFiles(files, vanity.NotGoogleProtobufDescriptorProto) for _, opt := range []func(*descriptor.FileDescriptorProto){ vanity.TurnOnGoStringAll, vanity.TurnOffGoGettersAll, vanity.TurnOffGoStringerAll, vanity.TurnOnMarshalerAll, vanity.TurnOnStringerAll, vanity.TurnOnUnmarshalerAll, vanity.TurnOnSizerAll, } { vanity.ForEachFile(files, opt) } resp := command.Generate(req) command.Write(resp) }
func main() { req := command.Read() files := req.GetProtoFile() files = vanity.FilterFiles(files, vanity.NotGoogleProtobufDescriptorProto) vanity.ForEachFile(files, vanity.TurnOnMarshalerAll) vanity.ForEachFile(files, vanity.TurnOnSizerAll) vanity.ForEachFile(files, vanity.TurnOnUnmarshalerAll) vanity.ForEachFile(files, vanity.TurnOffGoEnumPrefixAll) vanity.ForEachFile(files, vanity.TurnOffGoEnumStringerAll) vanity.ForEachFile(files, vanity.TurnOnEnumStringerAll) vanity.ForEachFile(files, vanity.TurnOnEqualAll) vanity.ForEachFile(files, vanity.TurnOnGoStringAll) vanity.ForEachFile(files, vanity.TurnOffGoStringerAll) for _, file := range files { if strings.HasSuffix(file.GetName(), "struct.proto") { // TODO struct can also get a compare method when // https://github.com/gogo/protobuf/issues/221 is fixed continue } vanity.TurnOnCompareAll(file) } for _, file := range files { if strings.HasSuffix(file.GetName(), "timestamp.proto") || strings.HasSuffix(file.GetName(), "duration.proto") { continue } vanity.TurnOnStringerAll(file) vanity.TurnOnPopulateAll(file) } resp := command.Generate(req) command.Write(resp) }
func main() { req := command.Read() files := req.GetProtoFile() files = vanity.FilterFiles(files, vanity.NotInPackageGoogleProtobuf) resp := command.Generate(req) msgs := []string{} for _, file := range files { if file.GetPackage() == "fuzztests" { for _, message := range file.GetMessageType() { msgs = append(msgs, "func() Message { return &"+message.GetName()+"{} }") } } } content := ` // Code generated by protoc-gen-gogomsglist. // DO NOT EDIT! package fuzztests type Message interface { Reset() String() string ProtoMessage() } var NewFuncs = []func() Message { ` + strings.Join(msgs, ",\n") + `, }` newFile := &plugin.CodeGeneratorResponse_File{ Name: proto.String("./msglist.gen.go"), Content: proto.String(content), } resp.File = []*plugin.CodeGeneratorResponse_File{newFile} command.Write(resp) }
func main() { req := command.Read() files := req.GetProtoFile() files = vanity.FilterFiles(files, vanity.NotGoogleProtobufDescriptorProto) vanity.ForEachFile(files, vanity.TurnOnMarshalerAll) vanity.ForEachFile(files, vanity.TurnOnSizerAll) vanity.ForEachFile(files, vanity.TurnOnUnmarshalerAll) vanity.ForEachFieldInFilesExcludingExtensions(vanity.OnlyProto2(files), vanity.TurnOffNullableForNativeTypesWithoutDefaultsOnly) vanity.ForEachFile(files, vanity.TurnOffGoUnrecognizedAll) vanity.ForEachFile(files, vanity.TurnOffGoEnumPrefixAll) vanity.ForEachFile(files, vanity.TurnOffGoEnumStringerAll) vanity.ForEachFile(files, vanity.TurnOnEnumStringerAll) vanity.ForEachFile(files, vanity.TurnOnEqualAll) vanity.ForEachFile(files, vanity.TurnOnGoStringAll) vanity.ForEachFile(files, vanity.TurnOffGoStringerAll) vanity.ForEachFile(files, vanity.TurnOnStringerAll) resp := command.Generate(req) command.Write(resp) }
func main() { req := command.Read() files := req.GetProtoFile() files = vanity.FilterFiles(files, vanity.NotInPackageGoogleProtobuf) for _, opt := range []func(*descriptor.FileDescriptorProto){ vanity.TurnOffGoGettersAll, // Currently harms readability. // vanity.TurnOffGoEnumPrefixAll, // `String() string` is part of gogoproto.Message, so we need this. // vanity.TurnOffGoStringerAll, // Maybe useful for tests? Not using currently. // vanity.TurnOnVerboseEqualAll, // Incompatible with oneof, and also not sure what the value is. // vanity.TurnOnFaceAll, // Requires that all child messages are generated with this, which // is not the case for Raft messages which wrap raftpb (which // doesn't use this). // vanity.TurnOnGoStringAll, // Not useful for us. // vanity.TurnOnPopulateAll, // Conflicts with `GoStringerAll`, which is enabled. // vanity.TurnOnStringerAll, // This generates a method that takes `interface{}`, which sucks. // vanity.TurnOnEqualAll, // Not useful for us. // vanity.TurnOnDescriptionAll, // vanity.TurnOnTestGenAll, // vanity.TurnOnBenchGenAll, vanity.TurnOnMarshalerAll, vanity.TurnOnUnmarshalerAll, vanity.TurnOnSizerAll, // We want marshalled protobufs to be deterministic so that they can be // compared byte-for-byte. At the time of writing, this is depended upon by // the consistency checker. vanity.TurnOnStable_MarshalerAll, // Enabling these causes `String() string` on Enums to be inlined. // Not worth it. // vanity.TurnOffGoEnumStringerAll, // vanity.TurnOnEnumStringerAll, // Not clear that this is worthwhile. // vanity.TurnOnUnsafeUnmarshalerAll, // vanity.TurnOnUnsafeMarshalerAll, // Something something extensions; we don't use 'em currently. // vanity.TurnOffGoExtensionsMapAll, vanity.TurnOffGoUnrecognizedAll, // Adds unnecessary dependency on golang/protobuf. // vanity.TurnOffGogoImport, } { vanity.ForEachFile(files, opt) } resp := command.Generate(req) command.Write(resp) }
func main() { command.Write(command.Generate(command.Read())) }