npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

go-template

v0.1.7

Published

Template for generating Go module based on async api

Downloads

22

Readme

Overview

This template generates a Go module that uses watermill as the messaging middleware

Technical requirements

Supported protocols

Currently this template supports AMQP subscribers

How to use the template

This template must be used with the AsyncAPI Generator. You can find all available options here.

CLI

This template has been tested to generate an AMQP subscriber for this asyncapi.yaml file

Run the following command to generate a Go module

npm install -g @asyncapi/generator
# clone this repository and navigate to this repository
ag test/asyncapi.yaml @asyncapi/go-watermill-template -o /path/to/generated-code -p moduleName=your-go-module-name

Following are the options that can be passed to the generator

  1. moduleName: name of the go module to be generated

How to use the generated code

The above code currently generates a Go module that has a AMQP subscriber.

Pre-requisites

To run the generated code the following needs to be installed

  1. go 1.16 +
  2. rabbitmq-server OR docker
Running the code
  1. Navigate to the path where the code was generated
  2. Run the following commands to download the dependencies
go mod download
go mod tidy
  1. Currently the code does not utilize the server bindings to generate the server URI. It is currently hardcoded to point to a local instance of rabbitmq. It is hardcoded as "amqp://guest:guest@localhost:5672/" at <generated-code>/config/server.go. Change it as per your rabbitmq instance requirements
  2. Finally to execute the code run
go run main.go
  1. 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
  2. Create a queue as per the AsyncAPI spec. This can be done either of the following ways
    • Using the UI: Refer to this article 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 \
       http://localhost:15672/api/queues/%2f/<queue-name> \
       -H 'cache-control: no-cache' \
       -H 'content-type: application/json' \
       -d '{
     "auto_delete":false,
     "durable":true
     }'
  3. 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 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 \
       http://localhost:15672/api/exchanges/%2f/amq.default/publish \
       -H 'cache-control: no-cache' \
       -H 'content-type: application/json' \
       -d ' {
     "properties":{},
     "routing_key":"light/measured",
     "payload":"{\"id\":1,\"lumens\":2,\"sentAt\":\"2021-09-21\"}",
     "payload_encoding":"string"
     }'
  4. Check the output at the terminal where go run main.go was running and the published message should be printed

Template configuration

You can configure this template by passing different parameters in the Generator CLI: -p PARAM1_NAME=PARAM1_VALUE -p PARAM2_NAME=PARAM2_VALUE

|Name|Description|Required|Example| |---|---|---|---| |moduleName|Name for the generated Go module|false|my-app|