gofasta init
Initializes an existing Gofasta project that was cloned from a repository or copied from another machine. This command creates the .env file, installs Go dependencies, runs Google Wire dependency injection generation, conditionally runs gqlgen GraphQL code generation (if gqlgen.yml exists), runs database migrations, and verifies the project builds successfully.
Use this command instead of gofasta new when you already have the project source code and just need to set up the development environment.
Usage
gofasta initRun this command from the root directory of your Gofasta project (the directory containing go.mod).
This command takes no flags.
Examples
Initialize a freshly cloned project:
git clone https://github.com/myorg/myapp.git
cd myapp
gofasta initWhat It Does
When you run gofasta init, the CLI performs the following steps in order:
- Create .env file — copies
.env.exampleto.envso you have a working environment configuration - Install dependencies — runs
go mod tidyto download and synchronize all Go module dependencies - Generate Wire code — runs
go tool wire ./app/di/to generate the dependency injection container from your provider definitions - Generate GraphQL code (only if
gqlgen.ymlexists) — runsgo tool gqlgen generateto create Go types and resolvers from your.graphqlsschema files. This step is automatically skipped for REST-only projects that were created without--graphql. - Run migrations — runs
migrate -path db/migrations -database <url> upto apply all pending database migrations - Verify build — runs
go build ./...to confirm the project compiles successfully
When to Use
| Scenario | Command |
|---|---|
| Starting a brand-new project from scratch | gofasta new myapp |
| Cloning an existing project from Git | gofasta init |
Pulling changes that modified wire.go or GraphQL schemas | gofasta init |
| Setting up the project on a new machine | gofasta init |
Related
- gofasta new — create a new project from scratch
- gofasta wire — regenerate only Wire DI code
- gofasta dev — start the development server
- Installation
Last updated on