Skip to content

Commit

Permalink
feat: contribution guide
Browse files Browse the repository at this point in the history
  • Loading branch information
anandsunderraman committed Apr 8, 2022
1 parent d024857 commit cacb656
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 7 deletions.
34 changes: 28 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,22 @@

## Overview

This template generates a Go module that uses [watermill](https://github.com/ThreeDotsLabs/watermill) as the messaging middleware
This template generates a Go module that uses [watermill](https://github.com/ThreeDotsLabs/watermill) as library for building event-driven applications

## Template Output

The `go` code generated by this template has the following structure

- __asyncapi__
- [handlers.go](asyncapi/handlers.go) -- handlers for publishers and subscribers
- [payloads.go](asyncapi/payloads.go) -- generated `go` structs using Modelina
- [publishers.go](asyncapi/publishers.go)
- [router.go](asyncapi/router.go) -- configures [watermill](https://watermill.io/) router, needed only for subscribers
- [server.go](asyncapi/server.go) -- server config
- [subscribers.go](asyncapi/subscribers.go)
- [go.mod](go.mod)
- [go.sum](go.sum)
- [main.go](main.go)

## Technical requirements

Expand All @@ -17,7 +32,10 @@ This template generates a Go module that uses [watermill](https://github.com/Thr

## Supported protocols

Currently this template supports AMQP subscribers
| Protocol | Subscriber | Publishers |
|---|---|---|
| AMQP | - [x] | - [x] |


## How to use the template

Expand Down Expand Up @@ -62,14 +80,14 @@ go mod tidy
```bash
go run main.go
```
5. Running local instance of `rabbitmq`, navigate to it using `http://localhost:15672/` with username and password `guest`/ `guest` (These are default rabbitmq credentials).
5. Running local instance of `rabbitmq`, navigate to it using `http://localhost:15672/` with username and password `guest`/ `guest` (These are default rabbitmq credentials).
FYI one can start an instance of `rabbitmq` using `docker` as follow
```
docker run -d -p 15672:15672 -p 5672:5672 rabbitmq:3-management
```
6. Create a queue as per the AsyncAPI spec.
6. Create a queue as per the AsyncAPI spec.
This can be done either of the following ways
- Using the UI: Refer to this [article](https://www.cloudamqp.com/blog/part3-rabbitmq-for-beginners_the-management-interface.html) that walks through the process of how this can be done in the UI / RabbitMQ Admin
- Using the UI: Refer to this [article](https://www.cloudamqp.com/blog/part3-rabbitmq-for-beginners_the-management-interface.html) that walks through the process of how this can be done in the UI / RabbitMQ Admin
- `cURL` request. Default rabbitmq user is `guest` and password is `guest`
```
curl --user <rabbit-user>:<rabbit-password> -X PUT \
Expand All @@ -82,7 +100,7 @@ go run main.go
}'
```
7. Publish a message to the queue as per the AsyncAPI spec. This can be done either of the following ways
- Using the UI: Refer to this [article](https://www.cloudamqp.com/blog/part3-rabbitmq-for-beginners_the-management-interface.html) that walks through the process of how this can be done in the UI / RabbitMQ Admin
- Using the UI: Refer to this [article](https://www.cloudamqp.com/blog/part3-rabbitmq-for-beginners_the-management-interface.html) that walks through the process of how this can be done in the UI / RabbitMQ Admin
- `cURL` request. Default rabbitmq user is `guest` and password is `guest`
```
curl --user <rabbit-user>:<rabbit-password> -X POST \
Expand All @@ -105,3 +123,7 @@ You can configure this template by passing different parameters in the Generator
|Name|Description|Required|Example|
|---|---|---|---|
|moduleName|Name for the generated Go module|false|`my-app`|

## Contribution guide

If you are interested in contributing to this repo refer to the [contributing](file://docs/contributing.md) docs
59 changes: 59 additions & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Contributing to go-watermill-template

First of all, thank you 🙇🏾‍♀️ for considering contributing to go-watermill-template; it needs all the help it can get!

This contribution guide is an extension to the core contributing guide that can be found [here](https://github.com/asyncapi/.github/blob/master/CONTRIBUTING.md). Please make sure you go through that beforehand. 🙂👍🏽

# Design

This repo was created from the template repo [template-for-generator-templates](https://github.com/asyncapi/template-for-generator-templates)

It has borrowed most of its concepts from it

Also check out this intial [video](https://www.youtube.com/watch?v=0ueeYM_0hck) where some of the concepts about a generator are discussed.

This generator has 2 main concepts

1. [template](https://github.com/asyncapi/go-watermill-template/tree/master/template)
2. [components](https://github.com/asyncapi/go-watermill-template/tree/master/components)

## Generated Code

The code generated by this template has the following structure

- __asyncapi__
- [handlers.go](asyncapi/handlers.go)
- [payloads.go](asyncapi/payloads.go)
- [publishers.go](asyncapi/publishers.go)
- [router.go](asyncapi/router.go)
- [server.go](asyncapi/server.go)
- [subscribers.go](asyncapi/subscribers.go)
- [go.mod](go.mod)
- [go.sum](go.sum)
- [main.go](main.go)

For each of the above files genenrated there should be a corresponding `.js` file under the templates direectory.
These template files parse take the parsed `asyncapi` doc as an input and then delegate to the responsibility of generating code to the react components under the `components` directory

## Development

It is not easy to write code in one language to generate code in another language.
In this case code is being written in `js` to generate `go` code.
Hence the best way to develop is to first develop the `go` code that one intends to generate.
One may consider this [repo](https://github.com/anandsunderraman/watermill-reference) for example where the working `go` code is first developed and is used as reference to author the above templates

## Dev Testing

In order to dev test the generated code consider running the npm command

```
npm run dev
```

This generates `go` code to the dir `output` based on the asyncapi sample file [here](https://github.com/asyncapi/go-watermill-template/blob/master/test/asyncapi.yaml)

Once the `go` code is generated, one can navigate to the `output` directory and run `go run main.go` to test the generated code.
Importantly one must have the appropriate broker or messaging software running locally to be able to test it successfully



2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"generate:readme:toc": "markdown-toc -i README.md",
"generate:assets": "npm run generate:readme:toc",
"bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION",
"devTest": "ag test/asyncapi.yaml ./ -o output --force-write",
"dev": "rm -rf output && ag test/asyncapi.yaml ./ -o output --force-write",
"test:components": "jest --coverage ./test/components"
},
"repository": {
Expand Down

0 comments on commit cacb656

Please sign in to comment.