The Runner service allows you to execute and share Go code snippets.
Protobuf contract: runner
The Runner service leverages the SSO service to verify administrative privileges when processing the DeleteCode RPC. This integration ensures that only authorized administrators can delete shared code snippets, enhancing security and access control within the application.
The Runner service uses Redis for caching shared code snippets to improve performance. When a code snippet is requested, the service first checks Redis. If the snippet is not found in the cache, it is retrieved from PostgreSQL and then stored in Redis for future requests. This reduces database load and speeds up data retrieval.
The Runner service uses Prometheus to collect metrics. For example:
curl http://localhost:9100/metrics
- gRPC / gRPC-gateway (for understanding)
- PostgreSQL
- Redis
- cleanenv
- slog
Before running the application, make sure Go are installed on your system.
- Clone the repository
git clone https://github.com/paniccaaa/runner.git
cd runner
- Create the .env, local.yaml and Makefile (see .example in repository). Also see sso.
- Run the app locally
make run
For detailed API documentation, you can view the Swagger documentation. Copy the contents of runner.swagger.json and paste it into Swagger Editor to explore and interact with the API.
- POST /run: Execute a Go code snippet.
- POST /share: Share a Go code snippet.
- GET /shared/{id}: Retrieve a shared Go code snippet by id.
- DELETE /shared/{id}?user_id={user_id}: Delete a shared Go code snippet by id (only for admins, see sso)
- RunCode
$ grpcurl -plaintext -d '{"code": "package main\nimport \"fmt\"\nfunc main() {\n fmt.Println(\"Hello RunCode!\")\n}"}' \
localhost:44000 runner.Runner/RunCode
{
"code": "package main\nimport \"fmt\"\nfunc main() {\n fmt.Println(\"Hello RunCode!\")\n}",
"output": "Hello RunCode!\n"
}
- ShareCode
$ grpcurl -plaintext -d '{"code": "package main\nimport \"fmt\"\nfunc main() {\n fmt.Println(\"Hello world! Test ShareCode\")\n}"}' \
localhost:44000 runner.Runner/ShareCode
{
"id": "2"
}
- GetCodeByID
$ grpcurl -plaintext -d '{"id": "2"}' localhost:44000 runner.Runner/GetCodeByID
{
"code": "package main\nimport \"fmt\"\nfunc main() {\n fmt.Println(\"Hello world! Test ShareCode\")\n}",
"output": "Hello world! Test ShareCode\n"
}
- DeleteCode
$ grpcurl -plaintext -d '{"id": 2, "user_id": 1}' localhost:44000 runner.Runner/DeleteCode
{
"success": true
}
See Makefile.example and make sure migrate on your system.
make mig_up
# and
make mig_down