项目作者: grofers

项目描述 :
Workflow based REST framework code generator
高级语言: Go
项目地址: git://github.com/grofers/go-codon.git
创建时间: 2017-04-18T14:09:43Z
项目社区:https://github.com/grofers/go-codon

开源协议:MIT License

下载


go-codon

Generates Go server code from a combination of REST and Workflow DSLs.

Build Status

A codon service has three components:

  • Server: Accepts and validates HTTP requests
  • Clients: Clients for upstream services which this service consumes
  • Workflows: Procedures for every REST endpoint of this server which consume Clients and other custom actions.

Server and Client side specifications are written in Swagger. Swagger code generation is done through go-swagger. Workflow is written in Flow, a Mistral inspired workflow specification in YAML. Its specification can be found here.

Check out wiki section for more information. Follow this tutorial for a very basic example on how to use this tool.

Installation

Set up your Golang development environment (Getting Started). Set your GOPATH and GOBIN directories. Also add GOBIN to your PATH so that golang tools can be used in command line.

Download the latest binary from Github releases and put it in your GOBIN directory. Or to install from source do:

  1. mkdir -p $GOPATH/src/github.com/grofers
  2. cd $GOPATH/src/github.com/grofers
  3. git clone git@github.com:grofers/go-codon.git
  4. cd go-codon
  5. make install

Example

This is what a workflow looks like (for an API to get posts and the comments for each post concurrently):

  1. name: get_posts_comments
  2. start:
  3. - get_posts
  4. tasks:
  5. get_posts:
  6. action: clients.jplaceholder.get_posts
  7. input:
  8. userId: <%jmes main.userId %>
  9. publish:
  10. posts: <%jmes action %>
  11. on-success:
  12. - get_all_comments: true
  13. get_comments:
  14. action: clients.jplaceholder.get_comments
  15. input:
  16. postId: <%jmes main.postId %>
  17. publish:
  18. comments: <%jmes action %>
  19. get_all_comments:
  20. with-items: <%jmes main.posts %>
  21. loop:
  22. task: get_comments
  23. input:
  24. postId: <%jmes item.id %>
  25. publish:
  26. combined: <%jmes {"post_details":item,"comments":task.comments} %>
  27. output:
  28. body: <%jmes main.combined %>
  29. status_code: 200

To run this example checkout examples.

Projects go-codon would not exist without

(Or just projects I am really thankful for)

  • go-swagger: Provides code generators for client and server side components using Swagger specification.
  • go-jmespath: Allows for easy querying and manipulation of json objects in workflows.
  • Pongo2: Django template renderer. Used for templates and workflow expressions in codon.
  • Mistral DSL: A workflow spec used for infrastructure orchestration. Codon’s workflow DSL is inspired from Mistral’s but modified for use in REST context.
  • mapstructure