Skip to content

Zenithar/gene

 
 

Repository files navigation

GoDoc Build Status

gene

Tired of bootstrapping?

Json-schema based code generation with Go (golang).

Why Code Generation?

Whenever a bootstrap is required for a project we are hustling with creating the required folder, files, configs, api function, endpoints, clients, tests etc...

This package aims to ease that pain

What is JSON-Schema?

JSON Schema specifies a JSON-based format to define the structure of your data for various cases, like validation, documentation, and interaction control. A JSON Schema provides a contract for the JSON data required by a given application, and how that data can be modified.

TLDR: here is an example twitter.json

Features

Models

  • Creating Models from json-schema definitions
  • Creating Validations for Models from json-schema definitions
  • Creating Constants for Model properties from json-schema definitions
  • Creating JSON Tags for Model properties from json-schema definitions
  • Adding golint-ed Documentations to the Models, Functions and Exported Variables
  • Creating Constructor Functions for Models with their default values from json-schema definitions

SQL

  • Creating Insert, Update, Delete, Select sql.DB.* compatible plain SQL statements without any reflection

Tests

  • Providing simple Assert, Ok, Equals test functions for the app

Workers

API

  • Creating rpc api endpoints for Create, Update, Select, Delete operations for every definition in json-schema

Client

  • Creating Client code for communication with your endpoints

CMD

  • Creating basic cli for the worker

Errors

  • Creating idiomatic Go Errors for the api, validations etc.

Tests

  • Creating tests for the generated api endpoints

Install

Package itself is not go gettable, get the cli for generating your app

go install github.com/cihangir/gene/cmd/gene

Usage

After having gene executable in your path Pass schema flag for your base json-schema, and target as the existing path for your app

gene -schema ./example/twitter.json -target ./example/

For now, it is generating the following folder/file structure

./src/github.com/cihangir/gene/example
├── twitter
│   ├── cmd
│   │   └── twitter
│   │       └── main.go
│   ├── db
│   │   ├── 001-twitter_db_roles.sql
│   │   ├── 002-twitter_db_database.sql
│   │   ├── Dockerfile
│   │   ├── account
│   │   │   ├── 004-schema.sql
│   │   │   ├── 005-account-sequence.sql
│   │   │   ├── 005-profile-sequence.sql
│   │   │   ├── 006-account-types.sql
│   │   │   ├── 007-account-table.sql
│   │   │   ├── 007-profile-table.sql
│   │   │   ├── 008-account-constraints.sql
│   │   │   └── 008-profile-constraints.sql
│   │   ├── create.sh
│   │   └── tweet
│   │       ├── 004-schema.sql
│   │       ├── 005-tweet-sequence.sql
│   │       ├── 007-tweet-table.sql
│   │       └── 008-tweet-constraints.sql
│   ├── errors
│   │   ├── account.go
│   │   ├── profile.go
│   │   └── tweet.go
│   ├── models
│   │   ├── account.go
│   │   ├── account_rowscanner.go
│   │   ├── account_statements.go
│   │   ├── profile.go
│   │   ├── profile_rowscanner.go
│   │   ├── profile_statements.go
│   │   ├── tweet.go
│   │   ├── tweet_rowscanner.go
│   │   └── tweet_statements.go
│   └── workers
│       └── twitter
│           ├── api
│           │   ├── account.go
│           │   ├── config.go
│           │   ├── profile.go
│           │   └── twitter.go
│           └── clients
│               ├── account.go
│               ├── profile.go
│               └── tweet.go
└── twitter.json

12 directories, 37 files

About

Tired of bootstrapping? Code generation for projects.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%