gene

package module
v0.0.0-...-bcdf8a7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2015 License: MIT Imports: 0 Imported by: 0

README

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

Documentation

Overview

Package gene helps you with creating the required folder, files, configs, api function, endpoints, clients, tests etc...

Directories

Path Synopsis
cmd
gene
Package main provides cli for gene package
Package main provides cli for gene package
genestruct
Package main provides cli for gene structs package
Package main provides cli for gene structs package
db
Package db provides a simple interface for the db operations
Package db provides a simple interface for the db operations
orm
example
twitter/models
Generated struct for Account.
Generated struct for Account.
generators
clients
Package clients generates clients for the generated api
Package clients generates clients for the generated api
common
Package common provides common operation helpers to the generators
Package common provides common operation helpers to the generators
errors
Package errors generates the common errors for the modules
Package errors generates the common errors for the modules
js
models
Package models creates the models for the modules
Package models creates the models for the modules
models/constants
Package constants generates the constant variables for a model/schema
Package constants generates the constant variables for a model/schema
models/constructors
Package constructors generates the constructors for given schema/model
Package constructors generates the constructors for given schema/model
sql/statements
Package statements creates sql statements for the given schema Currently it provides basic crud operations.
Package statements creates sql statements for the given schema Currently it provides basic crud operations.
tests
Package tests creates tests files for the given schema
Package tests creates tests files for the given schema
Package helpers provides helper functions for other subpackages
Package helpers provides helper functions for other subpackages
Package request provides a simple Option for requst handling
Package request provides a simple Option for requst handling
Package writers handles the file write operations
Package writers handles the file write operations

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL