Skip to content

yangyuqian/genus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  • Template Wrapper

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

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

    • Golang helper funcs
  • Generation Plan Specification

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

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

Releases

No releases published

Packages

No packages published