Skip to content

go-generation/go-mvc

Repository files navigation

GO-MVC

*** Disclaimer *** There are no guarantees of API stability until the first major version is released. Think of the current state as an alpha-phase product looking for validation from users about what features make sense and what the best UX is for those features.

Installation

  • set up your GOPATH
  • make sure your regular PATH includes the go binary folder e.g. /whereveryouinstalled/go/bin
  • download dependencies
go get golang.org/x/tools/cmd/goimports
  • download cli
go get -u github.com/go-generation/go-mvc/cmd/gomvc

Commands

  • gomvc application Generate application files
  • gomvc help Help about any command
  • gomvc oa Generate controllers from an OpenAPI yml file
  • gomvc resource Generate resource files
  • gomvc seed Generate seed files
  • gomvc swagger Generate controllers from a v2 Swagger yml file

Usage

Create an application:

$ mkdir yourapplication && cd yourapplication
$ gomvc application yourapplication

Optionally create controllers from your OpenAPI or Swagger 2.0 yaml spec (json support is coming):

$ gomvc oa --spec path/to/openapi.yml

or

$ gomvc swagger --spec path/to/swagger.yml

Create more resources:

$ gomvc resource dogs

Swagger vs OpenAPI Disclaimer

For ease of parsing, the gomvc swagger command currently converts the Swagger spec into an OpenAPI 3 spec. This is done by an underlying library gomvc uses which attempts to convert backwards compatible aspects of the spec. As such there may be some side effects or ignored properties. For example, a Swagger spec lists its reused parameters in a top level section called "parameters". In OA3, everything is nested under the "components" section. When resolving object/schema refs, you may find missing elements because it will try to look for parameters under "#/components/parameters" and not #/parameters".

Generated Application Dependencies

As of now, gomvc assumes you will want to use the following dependencies:

Example steps: using sqlboiler

  1. Generate application: gomvc application petstore --dest ~/Code/petstore
  2. Design your SQL schema or at least one table
  3. Create a migration per table: migrate create -ext sql -dir migrations -seq create_users_table
  4. Fill the migration file with your SQL commands e.g. CREATE USERS (etc...)
  5. Migrate your local database: migrate -database YOUR_DATBASE_URL -path PATH_TO_YOUR_MIGRATIONS up
  6. Install sqlboiler by running make dev-dependencies
  7. Create a sqlboiler configuration per https://github.com/volatiletech/sqlboiler#getting-started (will be automatically done for you in future GO-MVC release)
  8. Start your application so that you have postgres running: docker-compose up
  9. Run sqlboiler: sqlboiler psql
  10. Run gomvc resource {{tableName}} for each of the tables you want to create an endpoint for.
  11. Verify naming conventions align with what sqlboiler generated. You might need to edit the generated controllers.
  12. Generate seeder to fill DB with test data (assumes models dir exists in your app directory): gomvc seed.
  13. Continue dev-ing as you would normally

If you're managing your schema independently, you can completely remove the migrate dependency from both your workflow and the app but you can still use sqlboiler regardless.

About

golang code-generation meta-framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages