Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cmd/protoc-gen-elixir-grpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ plugins:

Server modules are generated into the same directory structure as the protobuf definitions, with `.server.pb.ex` suffix.

If you enable Buf's top-level `clean: true`, configure this plugin's `out` as a generated-only directory. Buf deletes each plugin `out` directory before invoking the plugin, so pointing `out` at a directory that also contains hand-written handlers will delete those files before this generator runs.

```yaml
version: v2
clean: true
plugins:
- local: protoc-gen-elixir-grpc
out: lib/generated_grpc
```

If generated stubs and hand-written handlers share the same output tree, keep `clean: false`.

### Configuration Options

You can configure the plugin using parameters:
Expand Down
26 changes: 16 additions & 10 deletions cmd/protoc-gen-elixir-grpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
// - local: protoc-gen-elixir-grpc
// out: lib
//
// If you use buf's top-level clean: true, set out to a generated-only
// directory. Buf deletes each plugin out directory before invoking the plugin.
// Do not point out at a directory that also contains hand-written handlers.
//
// This generates server module definitions for the Protobuf services
// defined by file.proto. If file.proto defines the Greeter service, the
// invocations above will write output to:
Expand Down Expand Up @@ -49,15 +53,15 @@ var (
)

const (
filenameSuffix = ".ex"
serverSuffix = "Server"
defaultPackagePrefix = ""
packagePrefixFlag = "package_prefix"
handlerModulePrefixFlag = "handler_module_prefix"
serverModulePrefixFlag = "server_module_prefix"
httpTranscodeFlag = "http_transcode"
codecsFlag = "codecs"
compressorsFlag = "compressors"
filenameSuffix = ".ex"
serverSuffix = "Server"
defaultPackagePrefix = ""
packagePrefixFlag = "package_prefix"
handlerModulePrefixFlag = "handler_module_prefix"
serverModulePrefixFlag = "server_module_prefix"
httpTranscodeFlag = "http_transcode"
codecsFlag = "codecs"
compressorsFlag = "compressors"

usage = "\n\nFlags:\n -h, --help\tPrint this help and exit.\n --version\tPrint the version and exit.\n --handler_module_prefix\tCustom Elixir module prefix for handler modules instead of protobuf package.\n --server_module_prefix\tCustom Elixir module prefix for server modules instead of protobuf package.\n --http_transcode\tEnable HTTP transcoding support (adds http_transcode: true to use GRPC.Server).\n --codecs\tComma-separated list of codec modules (e.g., 'GRPC.Codec.Proto,GRPC.Codec.WebText,GRPC.Codec.JSON').\n --compressors\tComma-separated list of compressor modules (e.g., 'GRPC.Compressor.Gzip')."
)
Expand Down Expand Up @@ -469,7 +473,9 @@ func generateFilePath(file *descriptorpb.FileDescriptorProto, opts GenerateOptio
baseFileName = baseFileName[:idx]
}

return strings.Join(pathParts, "/") + "/" + baseFileName + ".server.pb" + filenameSuffix
pathParts = append(pathParts, baseFileName+".server.pb"+filenameSuffix)

return strings.Join(pathParts, "/")
}

func toSnakeCase(s string) string {
Expand Down
4 changes: 2 additions & 2 deletions cmd/protoc-gen-elixir-grpc/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ end
assert.Equal(t, 1, len(rsp.File))

file := rsp.File[0]
assert.Equal(t, "/simple.server.pb.ex", file.GetName())
assert.Equal(t, "simple.server.pb.ex", file.GetName())

content := file.GetContent()
expected := `# Code generated by protoc-gen-elixir-grpc. DO NOT EDIT.
Expand Down Expand Up @@ -1075,7 +1075,7 @@ end
assert.Equal(t, 1, len(rsp.File))

file := rsp.File[0]
assert.Equal(t, "/payment.server.pb.ex", file.GetName())
assert.Equal(t, "payment.server.pb.ex", file.GetName())

content := file.GetContent()
expected := `# Code generated by protoc-gen-elixir-grpc. DO NOT EDIT.
Expand Down