Tired of bootstrapping?
Json-schema based code generation with Go (golang).
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
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
- 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
- Creating Insert, Update, Delete, Select sql.DB.* compatible plain SQL statements without any reflection
- Providing simple Assert, Ok, Equals test functions for the app
- Creating rpc api endpoints for Create, Update, Select, Delete operations for every definition in json-schema
- Creating Client code for communication with your endpoints
- Creating basic cli for the worker
- Creating idiomatic Go Errors for the api, validations etc.
- Creating tests for the generated api endpoints
Package itself is not go gettable, get the cli for generating your app
go install github.com/cihangir/gene/cmd/gene
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