0.1.3 • Published 6 years ago

generator-yogo v0.1.3

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

YoGo - golang code generator

Logo

YoGo is a Yeoman generator for GO language, which allows you to create projects in the form of:

  • Console (basic "Hello world") apps
  • REST API microservice
  • GO-KIT API microservice

This tool is meant for developers with the aim of removing the need to recreate each time the same skeleton when starting a new project. YoGo generates it for him, so he can focus on implementing logic in new app.

The Go Programming Language

Detail info you can find here.

Preparation for Usage

  • Install nodejs and npm on your system

  • Install yeoman on your system

npm install -g yo
  • Install generator-yogo
npm install generator-yogo
  • Launch the generator
yo yogo

Create new project

Create a new directory in GOPATH/src

cd $GOPATH/src
mkdir [ProjectName]
cd [ProjectName]
yo yogo

...and follow the interactive option selection

Structure of projects

  NOTE: the YoGo generator will only generate the directory hierarchy in *$GOPATH/src*.

Example console app

Example REST API microservice

FYI: Future development will add support for:

  • KAFKA producer
  • KAFKA consumer
  • etc.

Generate project via docker

If you want to generate your project in a Docker container (i.e. you don't want to install the YoGo dependencies on your machine):

  • install docker on your machine
  • clone this repository (git clone)
  • open a terminal and go to the generator-yogo folder
  • enter the following command:

for windows users

docker build -t generator-yogo:latest .
docker run -it --rm -v {YOUR_LOCAL_PATH}:/home/yeoman -e LOCAL_PATH=${LOCAL_PATH} --name generator-yogo-container generator-yogo

for Linux and MacOS users

make docker-build
make docker-run LOCAL_PATH=<YOUR_LOCAL_PATH>

where <YOUR_LOCAL_PATH> is the local folder where you want your project to be generated.

ATTENTION: if you have error like :

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

follow this link: https://apple.stackexchange.com/questions/254380/macos-sierra-invalid-active-developer-path

How to create a new package in an existing microservice.

Open a terminal, and from your project's folder run:

yo yogo:pkgg

You can choose the kind of package you want to create and use:

  • config
  • REST-API endpoint
  • GO-KIT endpoint

Config package

One possible type of package is config. In this case, the package will be generated with the following structure

NOTE: By default, YOGO generates a config.toml file with three ENV variables ( APP_PORT, KAFKA_BROKERS, SVC_TRACING_ZIPKIN )

Extend config package

You can add a config.toml file in your project's root folder with the list of ENV variables you need.

For example:
TEST=12345
TEST1=4567
TEST2=qwerty
DB_PORT=5432

After doing this, when generating the config package, all variables will be added on top of the default ones (APP_PORT, KAFKA_BROKERS, SVC_TRACING_ZIPKIN).