genus 基于模板的Go代码生成工具 genus

yangyuqian2017-02-18 03:11:52 • 2592 次点击    
这是一个分享于 2017-02-18 03:11:52 的项目,其中的信息可能已经有所发展或是发生改变。

License Build Status Go Report Card

中文版

List of Contents:

genus

A general code generation tools in Go.

New to code generation? Refer text/template for basic knowledge.

Why Another Generator?

Code generation has been becoming a popular way of metaprogramming in Go.

For example, when working with a ORM framework, you may want to create models with a given database schema with json tag support. it's trivial and burdensome when it comes with a database with hundreds even thousands of tables.

A code generation tool can help on this kind of issues through retriving database schema and rendering templates to go code.

However, before it turns into reality, you'll have to build a tool to

  • reading and organizing templates properly
  • formating the generated source code
  • fixing imports, especially removing unused imports
  • handle relative imports(imports among the generated code)
  • naming of generated file names

Today, generators are handling code generation in their own ways, which means that you can not generate models of Beego ORM with generators or gorm. It doesn't make sense to build a new generator becuase those models are generated from the same database schema.

Genus provides a clean way to perform code generation. Go to Examples to see more details.

Installation

Genus has built-in CLI support, you can install it by performing

go get -u github.com/yangyuqian/genus/cmd/genus

Features - V1

  • [x] Template Wrapper

    • [x] loading templates from diretories, files and bytes easily
    • [x] grouping templates for Go packages
    • [x] formating, fixing imports after code generation
  • [x] Generation Planner

    • [x] planning generation scenarios on template repository
    • [x] planner for regular files(non-Golang)
  • [x] Language specified helper funcs

    • [x] Golang helper funcs
  • [x] Generation Plan Specification

    • [x] JSON schema and validation support
    • [x] Reference and pointer support for complex specfications
  • [x] Command-line Interface

    • [x] accept context in JSON and do generation without writing any code
    • [x] create Generation Plan Specification of Database from given database

A general code generation tools for Go applicationsRead More

Latest commit to the master branch on 2-17-2017
Download as zip
授权协议:
MIT
开发语言:
Go 查看源码»
2592 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传