View Source Sidecar.GRPC.CodeGenerator (spawn v2.0.0-RC1)

Module for generating gRPC code from Protobuf files.

This module provides functionality to compile Protobuf files and generate gRPC-related code. It supports both gRPC and HTTP transcoding code generation.

Usage

  1. Call compile_protos/1 to generate gRPC code from Protobuf files.
  2. Ensure that Protobuf files are placed in the specified directory (priv/protos by default).

Summary

Functions

Compiles an Elixir module generated from Protobuf files and returns the compiled code.

Compiles Protobuf files and generates gRPC-related code.

Loads Elixir modules from the specified directory with a '.pb.ex' file extension.

Functions

after_compile_hook()

compile_modules(modules)

Compiles an Elixir module generated from Protobuf files and returns the compiled code.

Parameters:

  • module - The String of Elixir module code generated from Protobuf files.

Returns:

The compiled Elixir code.

Example:

module_code = Sidecar.Grpc.CodeGenerator.compile_modules(generated_code)

Raises:

Raises an error if there are issues during the compilation process.

compile_protos(opts \\ [])

Compiles Protobuf files and generates gRPC-related code.

### Options:

  • :protos_path - Include path of protobufs to generate (default: "priv/protos").
  • :output_path - Output path for generated code (default: "priv/protos/modules").
  • :http_transcoding_enabled - Enable HTTP transcoding (default: true).

### Example:

  Sidecar.Grpc.CodeGenerator.compile_protos(output_path: "custom_output", http_transcoding_enabled: false)

load_modules(opts \\ [])

Loads Elixir modules from the specified directory with a '.pb.ex' file extension.

Parameters

  • opts (KeywordList): Options for loading modules.
    • :output_path (String): Path to the directory containing the modules. Default is "/home/adrianosantos/workspaces/git/eigr/spawn/priv/protos/modules".

Returns

A list of strings, where each string represents the content of an Elixir module file.

Examples

opts = [output_path: "/path/to/modules"]
modules = load_modules(opts)
IO.inspect(modules)

This example loads Elixir modules from the specified directory "/path/to/modules" and prints the content of each module.

ls_r(path \\ ".")