msgen

command module
v0.0.0-...-f039ca6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2019 License: Apache-2.0 Imports: 1 Imported by: 0

README

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.

Documentation

Overview

Copyright © 2019 Dmytro Momot

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Directories

Path Synopsis
Package statik contains static assets.
Package statik contains static assets.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL