Go REST API project structure

Go REST API project structure

Explorer

  • .devcontainernew
  • devcontainer.jsonnew
  • .vscodenew
  • extensions.jsonnew
  • launch.jsonnew
  • settings.jsonnew
  • apinew
  • openapi.yamlnew
  • bin…new, not committed
  • tmp…new, not committed
  • cmd
  • internal
  • migrationsnew
  • 20261001093000_create_orders.sqlnew
  • 20261008110000_create_customers.sqlnew
  • embed.gonew
  • .air.tomlnew
  • .editorconfig
  • .envnew, not committed
  • .env.examplenew
  • .gitignore
  • .golangci.ymlnew
  • AGENTS.mdnew
  • CLAUDE.mdnew
  • compose.yamlnew
  • coverage.outnew, not committed
  • go.mod
  • go.sum
  • lefthook.ymlnew
  • Makefilenew
  • README.md
  • sqlc.yamlnew
  1. # Create the folder and the module (use the repository path you will push to)

    mkdir shop && cd shop && go mod init github.com/yourname/shop
  2. # Create the entry point

    mkdir -p cmd/api internal && touch cmd/api/main.go
  3. # Add the PostgreSQL driver

    go get github.com/jackc/pgx/v5
  4. # Track the migration and codegen tools in go.mod (Go 1.24+)

    go get -tool github.com/pressly/goose/v3/cmd/goose github.com/sqlc-dev/sqlc/cmd/sqlc
  5. # Run it

    go run ./cmd/api
  6. # Test everything, with the race detector

    go test -race ./...