Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/wzshiming/gen

Gen generates efficient web routing source code and documentation from annotations
https://github.com/wzshiming/gen

generate metaprogramming microservice no-framework openapi openapi3 restful swagger

Last synced: 17 days ago
JSON representation

Gen generates efficient web routing source code and documentation from annotations

Awesome Lists containing this project

README

        

# Gen - Tools for generating source code for microservices

Just write normal functions, and Gen generates efficient routing source code and documentation for it
Because the source code is generated, none of this affects runtime performance
The differences caused by each change in the tool are shown directly in the generated source code
generating clients is also supported

[![Build Status](https://travis-ci.org/wzshiming/gen.svg?branch=master)](https://travis-ci.org/wzshiming/gen)
[![Go Report Card](https://goreportcard.com/badge/github.com/wzshiming/gen)](https://goreportcard.com/report/github.com/wzshiming/gen)
[![GitHub license](https://img.shields.io/github/license/wzshiming/gen.svg)](https://github.com/wzshiming/gen/blob/master/LICENSE)

- [English](https://github.com/wzshiming/gen/blob/master/README.md)
- [简体中文](https://github.com/wzshiming/gen/blob/master/README_cn.md)

## Examples

'#' is the annotation, the annotation is the golang tag syntax, the only difference here is '#' wraps not '`'.

``` golang
// ItemService #path:"/item/"#
type ItemService struct {}

// Create a Item #route:"POST /"#
func (s *ItemService) Create(item *Item) (err error) {}

// Update the Item #route:"PUT /{item_id}"#
func (s *ItemService) Update(itemID int /* #name:"item_id"# */, item *Item) (err error) {}

// Delete the Item #route:"DELETE /{item_id}"#
func (s *ItemService) Delete(itemID int /* #name:"item_id"# */) (err error) {}

// Get the Item #route:"GET /{item_id}"#
func (s *ItemService) Get(itemID int /* #name:"item_id"# */) (item *ItemWithID, err error) {}

// List of the Item #route:"GET /"#
func (s *ItemService) List(offset, limit int) (items []*ItemWithID, err error) {}
```

1. Install gen tool `go get -v github.com/wzshiming/gen/cmd/gen`
2. Add gen tool to $PATH
3. Start it `gen run github.com/wzshiming/gen-examples/service/...`
4. Open [http://127.0.0.1:8080/swagger/?url=./openapi.json#](http://127.0.0.1:8080/swagger/?url=./openapi.json#) with your browser

[Examples](https://github.com/wzshiming/gen-examples/)

Or try to quickly build services from scratch

1. Make a directory `mkdir -p $(go env GOPATH)/src/gentest`
2. Change directory `cd $(go env GOPATH)/src/gentest/`
3. Define models
``` shell
cat > models.go <