View Source rebar3_go 🚀
A rebar3 plugin for managing Go modules in Erlang/OTP applications.
Features
- Adds Go modules to your Erlang/OTP project
- Compiles Go modules in your project
- Formats Go code in your project
- Tests Go modules in your project
- Supports standalone and release/umbrella applications
- Minimal configuration required
Requirements
- Erlang/OTP
- Go
Installation
%% Add the following to your rebar.config.
{project_plugins, [rebar3_go]}.
%% Optional: Add the following to your rebar.config
{provider_hooks, [
{pre, [
{compile, {go, compile}}
]}
]}.
Usage
# To add a Go module to your project (Standalone applications)
rebar3 go add -m <module_name>
# To add a Go module to your project (Release/Umbrella applications)
rebar3 go add -m <module_name> -a <app_name>
# To compile go modules
rebar3 go compile
# To format go code
rebar3 go fmt
# To test go modules
rebar3 go test
Directory Structure
Standalone App
.
├── src # Erlang source code
├── go.work # Go workspace definition
├── go_src # Go source code
│ ├── module1 # Go module 1
│ │ ├── main.go
│ │ └── go.mod
│ └── module2 # Go module 2
│ ├── main.go
│ └── go.mod
├── priv # Priv directory
│ └── go # Compiled Go code
│ ├── module1 # Compiled Go module 1
│ └── module2 # Compiled Go module 2
Release/Umbrella App
.
├── apps
│ ├── app1 # App 1
│ │ ├── src # Erlang source code
│ │ ├── go.work # Go workspace definition
│ │ ├── go_src # Go source code
│ │ │ ├── module1 # Go module 1
│ │ │ │ ├── main.go
│ │ │ │ └── go.mod
│ │ │ └── module2 # Go module 2
│ │ │ ├── main.go
│ │ │ └── go.mod
│ │ └── priv # Priv directory
│ │ └── go # Compiled Go code
│ │ ├── module1 # Compiled Go module 1
│ │ └── module2 # Compiled Go module 2
│ └── app2 # App 2
│ ├── src # Erlang source code
│ ├── go.work # Go workspace definition
│ ├── go_src # Go source code
│ │ ├── module1 # Go module 1
│ │ │ ├── main.go
│ │ │ └── go.mod
│ │ └── module2 # Go module 2
│ │ ├── main.go
│ │ └── go.mod
│ └── priv # Priv directory
│ └── go # Compiled Go code
│ ├── module1 # Compiled Go module 1
│ └── module2 # Compiled Go module 2
└── rebar.config
Commands
Add Module Command
The plugin adds a Go module to the project.
Syntax(Standalone app)
rebar3 go add -m <module_name>
Syntax(Release/Umbrella app)
rebar3 go add -m <module_name> -a <app_name>
First time adding a Go module to your project, the plugin creates a
go.work
file in the app root directory.In standalone applications, the
go.work
file will be created in the root directory of the application.
In release/umbrella applications, thego.work
file will be created in the root directory of the specified app.The plugin creates a
go_src/<module_name>
directory and creates themain.go
andgo.mod
files in it.The plugin adds the module name to the
go.work
file.
Compile Command
The plugin compiles the Go modules in the project.
Syntax
rebar3 go compile
The plugins goes through all applications in the project and checks if they have a
go_src
directory.If a
go_src
directory is found, the plugin compiles the Go module(s) in the directory else it skips the application.The plugin compiles the Go module(s) and copies the compiled code to the
priv/go
directory.
Format Command
The plugin formats the Go code in the project.
Syntax
rebar3 go fmt
The plugin runs the command
go fmt ./...
in each go module.
Test Command
The plugin tests the Go modules in the project.
Syntax
rebar3 go test
The plugin runs the command
go test ./... -cover
in each go module.The plugin aborts the whole operation if any of the tests fail.
Roadmap
- [x] Add module command
- [x] Compile command
- [x] Format command
- [x] Test module command
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Acknowledgments
Inspired by the needs of the Erlang/OTP community for reliable Go port communication.
Complementary Libraries
- Erlgo: Send and Receive messages between Erlang and Go.
Now go forth and make your Erlang and Go code talk to each other like old friends! 🚀✨