Categorygithub.com/go-generation/go-mvc
modulepackage
0.0.0-20230407165051-e539cc03f7dd
Repository: https://github.com/go-generation/go-mvc.git
Documentation: pkg.go.dev

# README

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.

# Packages

No description provided by the author

# Functions

No description provided by the author
Application is the cli command that creates new application.
Copy the src file to dst.
No description provided by the author
CreateFileFromString takes a filepath as the destination of the file to be created as well as the contents to be written to this file.
CreateRouter creates a router.go file to be used in the controllers directory.
CreateSeedCommand creates a single cmd that inserts records for all models.
CreateSeedersFromModels iterates through the given directory finds models the creates seed files in the given destination.
CreateSeederWithName creates a file with a single function.
No description provided by the author
No description provided by the author
No description provided by the author
G is the cli command that creates new g.
GenerateFromOA is the primary logic for the oa command, creating controllers.
No description provided by the author
No description provided by the author
GetGoType mutates the property type to determine GoType.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
todo: collect enums.
LoadSwaggerV2AsV3 takes the file path of a v2 Swagger file and returns a V3 representation.
LoadWithKin loads an OpenAPI spec into memory using the kin-openapi library.
Model is the cli command that creates new model.
No description provided by the author
No description provided by the author
NewGenerator is a constructor for Generator.
NewGoMVCConfig is a constructor for a gomvc configuration read into memory.
NewResponse is a constructor for the custom Response object.
NewResponses creates a list of responses from an OA3 response ref.
No description provided by the author
OA is the cli command that creates a router and controller functions from an OpenAPI file.
No description provided by the author
Resource is the cli command that creates new resource.
Root is the function called when running `gomvc`.
No description provided by the author
No description provided by the author
Seed is the cli command that creates new seeders based on structs in your application's "models" directory.
Swagger is the cli command that creates a router and controller functions from a swagger file.
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
File is a GoMVC specific type to store rendering meta data with the filenames.
Generator wraps functionality for reading and manipulating a single OpenAPI spec.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author