GithubHelp home page GithubHelp logo

dmitrymomot / msgen Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 6.05 MB

Generates a new golang microservice from template

License: Apache License 2.0

Go 43.17% Makefile 0.32% Smarty 56.51%
grpc golang go twirp generator microservice boilerplate-template pubsub nats-messaging redis-queue

msgen's Introduction

msgen

The simple tool to generate basic boilerplate of microservice. Not some special, just for my own needs.

Installation

go get -u github.com/dmitrymomot/msgen

Available options

msgen -h

Features

  • gRPC server & client
  • Twirp server
  • Pub/sup via NATS
  • Jobs queue via redis

Maybe better alternatives for you

Prerequisites

To use the tool you should have installed brotobuf and grpc-go

go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
go get -u google.golang.org/grpc

Protobuf is also available in MacOS through Homebrew:

brew install protobuf

Optional

Twirp - is a simple RPC framework built on protobuf

go get -u github.com/twitchtv/twirp/protoc-gen-twirp

Generate twirp files

make tproto

Protobuf validator by Envoyproxy*

# fetches this repo into $GOPATH
go get -d github.com/envoyproxy/protoc-gen-validate

# installs PGV into $GOPATH/bin
cd $GOPATH/src/github.com/envoyproxy/protoc-gen-validate && make build

Generate validator for your proto

make vproto

Usage

Let's create simple HTTP-RPC microservice with one method and exposed port via kubernetes load balancer service. To move ahead through the usage example you should install Twirp from optional dependencies section.

Run msgen --help to get more details about available options

msgen --twirp --rpc_methods=test_call --http_lb test-http-srv

The command above generates next files

├── Dockerfile
├── Makefile
├── README.md
├── go.mod
├── k8s.yml
├── logger
│   └── logger.go
├── main.go
├── pb
│   └── testhttpsrv
│       └── service.proto
└── service
    ├── service.go
    └── test_call.go

Move into test-http-srv and run service

cd test-http-srv && make build docker && docker run -d  -p 8888:8888 test-http-srv:latest

or if you have installed kubernetes

cd test-http-srv && make build docker deploy

Check it in terminal

curl --request POST \
  --url http://localhost:8888/twirp/testhttpsrv.Service/TestCall \
  --header 'content-type: application/json' \
  --data '{"str": "test string sample"}'

License

This library is licensed under the Apache 2.0 License.

msgen's People

Contributors

dmitrymomot avatar

Watchers

 avatar  avatar

Forkers

myorb

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.