gene

package module
v0.0.0-...-17fbf12 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2017 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 tinder.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/tinder.json -target ./example/

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

./src/github.com/cihangir/gene/example
├── db
│   ├── 001-tinder_db_roles.sql
│   ├── 002-tinder_db_database.sql
│   └── tinder_schema
│       ├── 004-schema.sql
│       ├── 005-account-sequence.sql
│       ├── 005-facebook_friends-sequence.sql
│       ├── 005-facebook_profile-sequence.sql
│       ├── 005-profile-sequence.sql
│       ├── 006-account-types.sql
│       ├── 007-account-table.sql
│       ├── 007-facebook_friends-table.sql
│       ├── 007-facebook_profile-table.sql
│       ├── 007-profile-table.sql
│       ├── 008-account-constraints.sql
│       ├── 008-facebook_friends-constraints.sql
│       ├── 008-facebook_profile-constraints.sql
│       └── 008-profile-constraints.sql
├── dockerfiles
│   ├── account
│   │   └── Dockerfile
│   ├── facebookfriends
│   │   └── Dockerfile
│   ├── facebookprofile
│   │   └── Dockerfile
│   └── profile
│       └── Dockerfile
├── errors
│   ├── account.go
│   ├── facebookfriends.go
│   ├── facebookprofile.go
│   └── profile.go
├── models
│   ├── account.go
│   ├── account_rowscanner.go
│   ├── facebookfriends.go
│   ├── facebookfriends_rowscanner.go
│   ├── facebookprofile.go
│   ├── facebookprofile_rowscanner.go
│   ├── markasrequest.go
│   ├── profile.go
│   └── profile_rowscanner.go
└── workers
    ├── account
    │   ├── interface.go
    │   ├── service.go
    │   ├── transport_http_client.go
    │   ├── transport_http_semiotics.go
    │   └── transport_http_server.go
    ├── cmd
    │   └── account
    │       └── main.go
    ├── facebookfriends
    │   ├── interface.go
    │   ├── service.go
    │   ├── transport_http_client.go
    │   ├── transport_http_semiotics.go
    │   └── transport_http_server.go
    ├── facebookprofile
    │   ├── interface.go
    │   ├── service.go
    │   ├── transport_http_client.go
    │   ├── transport_http_semiotics.go
    │   └── transport_http_server.go
    ├── kitworker
    │   ├── client.go
    │   ├── instrumenting.go
    │   ├── server.go
    │   └── zipkin.go
    └── profile
        ├── interface.go
        ├── service.go
        ├── transport_http_client.go
        ├── transport_http_semiotics.go
        └── transport_http_server.go

17 directories, 58 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
db
Package db provides a simple interface for the db operations
Package db provides a simple interface for the db operations
orm
example
tinder/models
Package models holds generated struct for Account.
Package models holds generated struct for Account.
generators
common
Package common provides common operation helpers to the generators
Package common provides common operation helpers to the generators
dockerfiles
Package dockerfiles generate docker file stubs
Package dockerfiles generate docker file stubs
errors
Package errors generates the common errors for the modules
Package errors generates the common errors for the modules
functions
Package functions generate functions for gene package system
Package functions generate functions for gene package system
js
kit
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
testsfuncs
Package testsfuncs generate basic test helper functions
Package testsfuncs generate basic test helper functions
plugins
gene-dockerfiles
Package main provides dockerfiles plugin for gene package
Package main provides dockerfiles plugin for gene package
gene-errors
Package main provides errors plugin for gene package
Package main provides errors plugin for gene package
gene-js
Package main provides kit plugin for gene package
Package main provides kit plugin for gene package
gene-jsbase
Package main provides jsbase plugin for gene package
Package main provides jsbase plugin for gene package
gene-kit
Package main provides kit plugin for gene package
Package main provides kit plugin for gene package
gene-models
Package main provides models plugin for gene package
Package main provides models plugin for gene package
gene-rows
Package main provides rows plugin for gene package
Package main provides rows plugin for gene package
gene-tests
Package main provides tests plugin for gene package
Package main provides tests plugin for gene package
gene-tests-funcs
Package main provides testsfuncs funcs plugin for gene package
Package main provides testsfuncs funcs plugin for gene package
Package utils provides helper functions for other subpackages
Package utils provides helper functions for other subpackages

Jump to

Keyboard shortcuts

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