### Start Server with Make
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/endpoints-test/websocket.md
Use this command to start the server. Ensure you have Make installed and the Makefile configured.
```bash
# Start server
make run
```
--------------------------------
### Create Project Interactively
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/creating-project/project-init.md
Use this command to start an interactive project setup guided by the CLI. It prompts for project name, framework, and database driver.
```bash
go-blueprint create
```
--------------------------------
### All Features Combined Example
Source: https://context7.com/melkeydev/go-blueprint/llms.txt
Demonstrates how to combine multiple flags and features for a comprehensive project setup, including framework, driver, Git, advanced options, and various features like HTMX, GitHub Actions, WebSockets, Tailwind, Docker, and React.
```bash
go-blueprint create \
--name my-app \
--framework chi \
--driver postgres \
--git commit \
--advanced \
--feature htmx \
--feature githubaction \
--feature websocket \
--feature tailwind \
--feature docker \
--feature react
```
--------------------------------
### Install Go Blueprint via Homebrew
Source: https://github.com/melkeydev/go-blueprint/blob/main/README.md
Installs go-blueprint using Homebrew. After installation, run 'go-blueprint create' in a new terminal.
```bash
brew install go-blueprint
```
```bash
go-blueprint create
```
--------------------------------
### Install Go Blueprint
Source: https://context7.com/melkeydev/go-blueprint/llms.txt
Install Go Blueprint using various methods including Go binary, NPM, Homebrew, or building from source. Verify the installation with the 'version' command.
```bash
go install github.com/melkeydev/go-blueprint@latest
```
```bash
npm install -g @melkeydev/go-blueprint
```
```bash
brew install go-blueprint
```
```bash
git clone https://github.com/melkeydev/go-blueprint
cd go-blueprint
go build && go install
```
```bash
go-blueprint version
```
--------------------------------
### Install Go-Blueprint from Source
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/installation.md
Installs the built Go-Blueprint binary system-wide, making it accessible from your PATH.
```bash
go install
```
--------------------------------
### Install Docker
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/blueprint-core/db-drivers.md
Use this command to download the Docker installation script.
```bash
curl -sLO get.docker.com
```
--------------------------------
### Install Go-Blueprint CLI Binary
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/installation.md
Installs the Go-Blueprint CLI tool as a binary. This command installs the Go-Blueprint binary, automatically binding it to your $GOPATH.
```bash
go install github.com/melkeydev/go-blueprint@latest
```
--------------------------------
### Makefile Run Target
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/react-vite.md
This target starts the Go backend server, installs frontend dependencies, and runs the Vite development server.
```makefile
run:
@go run cmd/api/main.go &
@npm install --prefix ./frontend
@npm run dev --prefix ./frontend
```
--------------------------------
### Install Go Blueprint via Go Install
Source: https://github.com/melkeydev/go-blueprint/blob/main/README.md
Installs the go-blueprint binary globally. Ensure your GOPATH is set and added to your PATH. For Zsh users, update ~/.zshrc and source it.
```bash
go install github.com/melkeydev/go-blueprint@latest
```
```bash
GOPATH=$HOME/go PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
```
```bash
source ~/.zshrc
```
--------------------------------
### Install Frontend Dependencies
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/react-vite.md
Install all required Node.js packages for the frontend project using npm.
```bash
npm install
```
--------------------------------
### Install Templ CLI
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/htmx-templ.md
Install the Templ CLI tool globally using go install. This is required for generating Go code from .templ files.
```bash
go install github.com/a-h/templ/cmd/templ@latest
```
--------------------------------
### Install Go-Blueprint via Homebrew
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/installation.md
Installs Go-Blueprint using Homebrew on macOS and Linux systems. Homebrew handles dependencies and updates automatically.
```bash
brew install go-blueprint
```
--------------------------------
### Select Advanced Features Non-Interactively (React + Vite)
Source: https://context7.com/melkeydev/go-blueprint/llms.txt
Scaffold a React frontend with Vite (TypeScript) by using the --feature react flag with --advanced. This sets up a 'frontend/' directory, configures environment variables, and provides an example API fetch. Remember to run 'npm install' and 'npm run dev' after creation.
```bash
go-blueprint create --name my-app --framework gin --driver postgres --git commit --advanced --feature react
# After creation:
cd my-app/frontend
npm install
npm run dev
```
--------------------------------
### Verify Go-Blueprint Installation
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/installation.md
Checks if the Go-Blueprint installation was successful by displaying its version information.
```bash
go-blueprint version
```
--------------------------------
### Git Initialization Options
Source: https://context7.com/melkeydev/go-blueprint/llms.txt
Control Git repository setup during project creation using the --git flag. Options include 'commit' for initial commit, 'stage' to stage files only, and 'skip' to disable Git initialization. Requires git user.name and user.email to be configured when not skipping.
```bash
# Init repo and create initial commit
go-blueprint create --name my-app --framework gin --driver postgres --git commit
# Init repo and stage files only (no commit)
go-blueprint create --name my-app --framework gin --git stage
# Skip git entirely
go-blueprint create --name my-app --framework gin --git skip
```
--------------------------------
### Install Go-Blueprint via NPM
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/installation.md
Installs Go-Blueprint globally using the Node.js package manager. This method is convenient for developers in JavaScript/Node.js environments.
```bash
npm install -g @melkeydev/go-blueprint
```
--------------------------------
### Run Vite Development Server
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/react-vite.md
Start the Vite development server for live reloading and local development. Access the application at http://localhost:5173.
```bash
npm run dev
```
--------------------------------
### Select Database Driver
Source: https://context7.com/melkeydev/go-blueprint/llms.txt
Use the --driver or -d flag to select a database driver. This installs the driver, generates database connection files, and a .env entry. Integration tests are generated for most drivers.
```bash
# PostgreSQL (pgx/v5)
go-blueprint create --name my-app --framework gin --driver postgres
```
```bash
# MySQL
go-blueprint create --name my-app -f chi -d mysql
```
```bash
# MongoDB
go-blueprint create --name my-app --framework fiber --driver mongo
```
```bash
# Redis
go-blueprint create --name my-app --framework echo --driver redis
```
```bash
# SQLite (no docker-compose, no integration tests)
go-blueprint create --name my-app --framework gin --driver sqlite
```
```bash
# ScyllaDB (GoCQL with ScyllaDB replacement)
go-blueprint create --name my-app --framework chi --driver scylla
```
--------------------------------
### Non-Interactive Project Creation with Go Blueprint
Source: https://context7.com/melkeydev/go-blueprint/llms.txt
Use this command to reproduce an exact project setup non-interactively, ideal for CI or team sharing. It specifies the project name, framework, database driver, and Git commit behavior.
```bash
go-blueprint create --name my-app --framework gin --driver postgres --git commit
```
--------------------------------
### Test Hello World Endpoint with CURL
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/endpoints-test/server.md
Use this curl command to send a GET request to the root endpoint of your application. Ensure your server is running on the specified port.
```bash
curl http://localhost:PORT
```
--------------------------------
### Run All Integration Tests
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/blueprint-core/db-drivers.md
Execute this command from the root directory to run all integration tests, which will automatically pull Docker images, start containers, run tests, and clean up.
```bash
make itest
```
--------------------------------
### Run Live Reloading with Air
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/creating-project/air.md
Execute the 'make watch' command to start Air. This command monitors specified directories for changes, automatically rebuilding and restarting your Go application. The output shows Air's initialization, file watching, build process, and application restarts upon detecting changes.
```bash
make watch
__ _ ___
/ /\ | | | |_)
/_/--\ |_| |_| \_ v1.51.0, built with Go go1.22.0
mkdir /home/ujstor/code/blueprint-version-test/ws-test4/tmp
watching .
watching cmd
watching cmd/api
watching cmd/web
watching cmd/web/assets
watching cmd/web/assets/js
watching internal
watching internal/database
watching internal/server
watching tests
!exclude tmp
building...
make[1]: Entering directory '/home/ujstor/code/blueprint-version-test/ws-test4'
Building...
Processing path: /home/ujstor/code/blueprint-version-test/ws-test4
Generated code for "/home/ujstor/code/blueprint-version-test/ws-test4/cmd/web/base.templ" in 914.556µs
Generated code for "/home/ujstor/code/blueprint-version-test/ws-test4/cmd/web/hello.templ" in 963.157µs
Generated code for 2 templates with 0 errors in 1.274392ms
make[1]: Leaving directory '/home/ujstor/code/blueprint-version-test/ws-test4'
running...
internal/server/routes.go has changed
building...
make[1]: Entering directory '/home/ujstor/code/blueprint-version-test/ws-test4'
Building...
Processing path: /home/ujstor/code/blueprint-version-test/ws-test4
Generated code for "/home/ujstor/code/blueprint-version-test/ws-test4/cmd/web/base.templ" in 907.426µs
Generated code for "/home/ujstor/code/blueprint-version-test/ws-test4/cmd/web/hello.templ" in 1.16142ms
Generated code for 2 templates with 0 errors in 1.527556ms
make[1]: Leaving directory '/home/ujstor/code/blueprint-version-test/ws-test4'
running...
```
--------------------------------
### Linux Makefile for Tailwind and Templ Compilation
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/tailwind.md
This Makefile automates the installation of templ and the Tailwind CLI, then compiles CSS and builds the Go application. It ensures dependencies are met before proceeding.
```bash
all: build
templ-install:
@if ! command -v templ > /dev/null; then \
read -p "Go's 'templ' is not installed on your machine. Do you want to install it? [Y/n] " choice; \
if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \
go install github.com/a-h/templ/cmd/templ@latest; \
if [ ! -x "$$(command -v templ)" ]; then \
echo "templ installation failed. Exiting..."; \
exit 1; \
fi; \
else \
echo "You chose not to install templ. Exiting..."; \
exit 1; \
fi; \
fi
tailwind-install:
@if [ ! -f tailwindcss ]; then curl -sL https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64 -o tailwindcss; fi
@chmod +x tailwindcss
build: tailwind-install templ-install
@echo "Building..."
@templ generate
@./tailwindcss -i cmd/web/styles/input.css -o cmd/web/assets/css/output.css
@go build -o main cmd/api/main.go
```
--------------------------------
### Select Advanced Features Non-Interactively (HTMX)
Source: https://context7.com/melkeydev/go-blueprint/llms.txt
Add HTMX support to your project using the --feature htmx flag along with --advanced. This includes necessary templating files and installs the templ engine. Remember to run 'templ generate' and 'make run' after creation.
```bash
go-blueprint create --name my-app --framework gin --driver postgres --git commit --advanced --feature htmx
# After creation:
cd my-app
go install github.com/a-h/templ/cmd/templ@latest
templ generate
make run
```
--------------------------------
### Non-Interactive Setup with Specific Advanced Features
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/advanced-flag.md
Configure a project non-interactively by specifying the --advanced flag along with individual --feature flags for granular control over which advanced features are included.
```bash
go-blueprint create --name my-project --framework chi --driver mysql --advanced --feature htmx --feature githubaction --feature websocket --feature tailwind
```
--------------------------------
### Select Advanced Features Non-Interactively (WebSocket)
Source: https://context7.com/melkeydev/go-blueprint/llms.txt
Add WebSocket support to your application by specifying the --feature websocket flag along with --advanced. This installs the necessary WebSocket library and configures a '/ws' endpoint.
```bash
go-blueprint create --name my-app --framework gin --driver postgres --git commit --advanced --feature websocket
```
--------------------------------
### Create Project with Advanced Features Enabled
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/creating-project/project-init.md
Initiate project creation with the `--advanced` flag to enable interactive selection of advanced features. This flag can be combined with other flags for a semi-interactive setup.
```bash
go-blueprint create --advanced
```
```bash
go-blueprint create --name my-project --framework chi --driver mysql --git commit --advanced
```
--------------------------------
### Makefile for Templ Automation
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/htmx-templ.md
Automates Templ CLI operations and Go builds. It checks for Templ installation and generates Go code before building the main application.
```makefile
all: build
templ-install:
@if ! command -v templ > /dev/null; then \
read -p "Go's 'templ' is not installed on your machine. Do you want to install it? [Y/n] " choice; \
if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \
go install github.com/a-h/templ/cmd/templ@latest; \
if [ ! -x "$$(command -v templ)" ]; then \
echo "templ installation failed. Exiting..."; \
exit 1; \
fi; \
else \
echo "You chose not to install templ. Exiting..."; \
exit 1; \
fi; \
fi
build: templ-install
@echo "Building..."
@templ generate
@go build -o main cmd/api/main.go
```
--------------------------------
### Sample ScyllaDB Health Check Output
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/endpoints-test/scylladb.md
This is an example of the JSON-like map structure returned by the Health function, indicating the status and details of the ScyllaDB cluster.
```json
{
"message": "It's healthy",
"status": "up",
"scylla_cluster_nodes_up": "3",
"scylla_cluster_nodes_down": "0",
"scylla_cluster_size": "1",
"scylla_current_datacenter": "datacenter1",
"scylla_current_time": "2024-11-04 22:59:21.69 +0000 UTC",
"scylla_health_check_duration": "16.896976ms",
"scylla_keyspaces": "6"
}
```
--------------------------------
### Sample Health Function Output
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/endpoints-test/sql.md
This is an example of the JSON-like map structure returned by the Health function, indicating the database connection status and various performance metrics.
```json
{
"idle": "1",
"in_use": "0",
"max_idle_closed": "0",
"max_lifetime_closed": "0",
"message": "It's healthy",
"open_connections": "1",
"status": "up",
"wait_count": "0",
"wait_duration": "0s"
}
```
--------------------------------
### NPM Cache Commands
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/react-vite.md
Provides essential npm commands for managing the package cache. Use these to verify cache integrity, view its contents, or clean it if installation issues arise.
```bash
# Check cache status
npm cache verify
# View cache contents
npm cache ls
# Clean cache if needed
npm cache clean --force
```
--------------------------------
### Select Advanced Features Non-Interactively (Tailwind CSS)
Source: https://context7.com/melkeydev/go-blueprint/llms.txt
Enable Tailwind CSS integration using the --feature tailwind flag with --advanced. This adds CSS input and output files. For standalone Tailwind CLI usage, install it from GitHub releases and run the provided command.
```bash
go-blueprint create --name my-app --framework chi --git commit --advanced --feature tailwind
# After creation — install Tailwind standalone CLI from GitHub releases, then:
./tailwindcss -i cmd/web/styles/input.css -o cmd/web/assets/css/output.css --watch
```
--------------------------------
### Build Go-Blueprint Binary from Source
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/installation.md
Compiles the Go-Blueprint source code into a binary.
```bash
go build
```
--------------------------------
### Project Structure Overview
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/blueprint-core/frameworks.md
This bash snippet illustrates the typical directory layout for a Go Blueprint project, highlighting the cmd, internal, and tests directories.
```bash
/(Root)
├── /cmd
│ └── /api
│ └── main.go
├── /internal
│ └── /server
│ ├── routes.go
│ ├── routes_test.go
│ └── server.go
├── go.mod
├── go.sum
├── Makefile
└── README.md
```
--------------------------------
### Sample Hello World Response
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/endpoints-test/server.md
This is the expected JSON output when the 'Hello World' endpoint is successfully accessed. It confirms the server is running and responsive.
```json
{"message": "Hello World"}
```
--------------------------------
### Select Web Framework
Source: https://context7.com/melkeydev/go-blueprint/llms.txt
Use the --framework or -f flag to select an HTTP routing framework. Supported options include chi, gin, fiber, gorilla/mux, httprouter, and standard-library.
```bash
# Gin
go-blueprint create --name my-app --framework gin
```
```bash
# Chi
go-blueprint create --name my-app -f chi
```
```bash
# Fiber (uses Fasthttp internally)
go-blueprint create --name my-app --framework fiber
```
```bash
# Standard library — no external dependency
go-blueprint create --name my-app --framework standard-library
```
```bash
# Echo
go-blueprint create --name my-app --framework echo
```
```bash
# Gorilla/Mux
go-blueprint create --name my-app --framework gorilla/mux
```
```bash
# HttpRouter
go-blueprint create --name my-app --framework httprouter
```
--------------------------------
### Navigate to Frontend Directory
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/react-vite.md
Change the current directory to the frontend project folder.
```bash
cd frontend
```
--------------------------------
### Create Project with Flags (Non-Interactive)
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/creating-project/project-init.md
Configure project creation non-interactively by specifying project name, framework, database driver, and Git commit option using flags.
```bash
go-blueprint create --name my-project --framework gin --driver postgres --git commit
```
--------------------------------
### JSON Serialization of Redis Health Data
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/endpoints-test/redis.md
An example demonstrating how Redis health data can be structured and serialized into JSON format for easier parsing and use in applications.
```json
{
"redis_health": {
"status": "up",
"message": "Redis connection pool utilization is high",
"stats": {
"version": "7.0.15",
"mode": "standalone",
"connected_clients": "10",
"memory": {
"used": {
"mb": "22.38",
"gb": "0.02"
},
"peak": {
"mb": "46.57",
"gb": "0.05"
},
"free": {
"mb": "1130.00",
"gb": "1.10"
},
"percentage": "1.98%"
},
"uptime_stats": "6 days, 3 hours, 37 minutes, 20 seconds",
"uptime": [
{
"day": "6"
},
{
"hour": "3"
},
{
"minute": "37"
},
{
"second": "20"
}
],
"pooling": {
"figures": {
"hits": "10",
"misses": "2",
"timeouts": "0",
"total": "4",
"stale": "9",
"idle": "5",
"active": "0",
"percentage": "62.50%"
},
"observed_total": "26"
}
}
}
}
```
--------------------------------
### Run Application
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/endpoints-test/web.md
Use this command to run the application. Observe the terminal log for HTTP request details.
```bash
make run
```
--------------------------------
### Enable Advanced Features Menu
Source: https://context7.com/melkeydev/go-blueprint/llms.txt
Use the --advanced flag to unlock an interactive multi-select TUI for advanced integrations. This can be combined with other flags for a non-interactive setup.
```bash
# Opens interactive multi-select for advanced features
go-blueprint create --advanced
# Semi-interactive: framework/driver/git from flags, advanced features from TUI
go-blueprint create --name my-app --framework chi --driver mysql --git commit --advanced
```
--------------------------------
### XML Serialization of Redis Health Data
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/endpoints-test/redis.md
An example demonstrating how Redis health data can be structured and serialized into XML format, offering an alternative to JSON for data exchange.
```xml
up
Redis connection pool utilization is high
7.0.15
standalone
10
22.38
0.02
46.57
0.05
1130.00
1.10
1.98%
6 days, 3 hours, 37 minutes, 20 seconds
6
3
37
20
10
2
0
4
9
5
0
62.50%
26
```
--------------------------------
### Running Integration Tests
Source: https://context7.com/melkeydev/go-blueprint/llms.txt
Execute integration tests for the database module by navigating to the internal database directory and running 'go test', or use the 'make itest' command from the project root.
```bash
cd my-app/internal/database
go test -v
# or from root:
make itest
```
--------------------------------
### Sample Raw Redis Health Check Output
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/endpoints-test/redis.md
This is an example of the raw JSON-like map structure returned by the Health function, containing various Redis health metrics.
```json
{
"redis_active_connections": "0",
"redis_connected_clients": "1",
"redis_hits_connections": "1",
"redis_idle_connections": "1",
"redis_max_memory": "0",
"redis_message": "Redis has been recently restarted",
"redis_misses_connections": "1",
"redis_mode": "standalone",
"redis_ping_response": "PONG",
"redis_pool_size_percentage": "0.42%",
"redis_stale_connections": "0",
"redis_status": "up",
"redis_timeouts_connections": "0",
"redis_total_connections": "1",
"redis_uptime_in_seconds": "55",
"redis_used_memory": "980704",
"redis_used_memory_peak": "980704",
"redis_version": "7.2.4"
}
```
--------------------------------
### Enable Advanced Features
Source: https://github.com/melkeydev/go-blueprint/blob/main/README.md
Run the create command with the --advanced flag to access additional features.
```bash
go-blueprint create --advanced
```
--------------------------------
### Dockerfile with React Frontend Build
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/docker.md
This Dockerfile demonstrates a multi-stage build for a Go application with a React frontend. It includes stages for building the Go backend, building the React frontend, and serving the frontend.
```dockerfile
FROM golang:1.24.4-alpine AS build
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o main cmd/api/main.go
FROM alpine:3.20.1 AS prod
WORKDIR /app
COPY --from=build /app/main /app/main
EXPOSE ${PORT}
CMD ["./main"]
FROM node:20 AS frontend_builder
WORKDIR /frontend
COPY frontend/package*.json ./
RUN npm install
COPY frontend/. .
RUN npm run build
FROM node:20-slim AS frontend
RUN npm install -g serve
COPY --from=frontend_builder /frontend/dist /app/dist
EXPOSE 5173
CMD ["serve", "-s", "/app/dist", "-l", "5173"]
```
--------------------------------
### Create Project Without Database
Source: https://context7.com/melkeydev/go-blueprint/llms.txt
Use the `--driver none` flag to create a new project without any database integration.
```bash
go-blueprint create --name my-app --framework gin --driver none
```
--------------------------------
### Dockerfile with Templ and Tailwind CSS
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/docker.md
This Dockerfile uses a two-stage build. The first stage compiles Go code, generates templ files, and builds Tailwind CSS. The second stage creates a minimal production image.
```dockerfile
FROM golang:1.24.4-alpine AS build
RUN apk add --no-cache curl libstdc++ libgcc
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go install github.com/a-h/templ/cmd/templ@latest && \
templ generate && \
curl -sL https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64-musl -o tailwindcss && \
chmod +x tailwindcss && \
./tailwindcss -i cmd/web/styles/input.css -o cmd/web/assets/css/output.css
RUN go build -o main cmd/api/main.go
FROM alpine:3.20.1 AS prod
WORKDIR /app
COPY --from=build /app/main /app/main
EXPOSE ${PORT}
CMD ["./main"]
```
--------------------------------
### Navigate to Project Directory
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/htmx-templ.md
Change to your project's root directory before running commands.
```bash
cd my-project
```
--------------------------------
### Run Database Integration Tests
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/blueprint-core/db-drivers.md
Navigate to the internal/database directory and execute this command to run integration tests. Alternatively, run 'make itest' from the root directory.
```bash
go test -v
```
--------------------------------
### Sample Terminal Log Output
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/endpoints-test/web.md
This log shows a successful POST request to the /hello endpoint, including status, size, and duration.
```bash
2024/05/28 20:42:06 "POST http://localhost:8070/hello HTTP/1.1" from 127.0.0.1:45494 - 200 24B in 53.23µs
```
--------------------------------
### Select Advanced Features Non-Interactively (Docker)
Source: https://context7.com/melkeydev/go-blueprint/llms.txt
Generate Docker configuration files by using the --feature docker flag with --advanced. This includes a multi-stage Dockerfile and a docker-compose.yml for projects using 'none' or 'sqlite' drivers.
```bash
go-blueprint create --name my-app --framework gin --driver none --git commit --advanced --feature docker
# Build and run:
cd my-app
docker-compose up --build
```
--------------------------------
### Clone Go-Blueprint Repository
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/installation.md
Clones the Go-Blueprint project from GitHub to build from source.
```bash
git clone https://github.com/melkeydev/go-blueprint
```
--------------------------------
### Recreate Project with --advanced Flag (Interactive)
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/advanced-flag.md
This command recreates a project with the same configuration semi-interactively, including all advanced features enabled by the --advanced flag.
```bash
go-blueprint create --name my-project --framework chi --driver mysql --advanced
```
--------------------------------
### Docker Compose Build and Run Commands
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/docker.md
These commands are used for building and running Docker Compose services. `--no-cache` ensures a fresh build, and `down --volumes` is useful for cleaning up leftover Docker resources.
```bash
docker compose build --no-cache && docker compose up
```
--------------------------------
### Dockerfile for Production Build
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/react-vite.md
Defines multi-stage Docker builds for both the Go backend and the React frontend. The final stage includes the production-ready frontend served via 'serve'.
```dockerfile
FROM golang:1.24.4-alpine AS build
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o main cmd/api/main.go
FROM alpine:3.20.1 AS prod
WORKDIR /app
COPY --from=build /app/main /app/main
EXPOSE ${PORT}
CMD ["./main"]
FROM node:20 AS frontend_builder
WORKDIR /frontend
COPY frontend/package*.json ./
RUN npm install
COPY frontend/. .
RUN npm run build
FROM node:20-slim AS frontend
RUN npm install -g serve
COPY --from=frontend_builder /frontend/dist /app/dist
EXPOSE 5173
CMD ["serve", "-s", "/app/dist", "-l", "5173"]
```
--------------------------------
### Display go-blueprint Version
Source: https://context7.com/melkeydev/go-blueprint/llms.txt
Retrieve the current binary version of go-blueprint by executing the 'go-blueprint version' command. The version is typically injected via ldflags during the build process by GoReleaser.
```bash
go-blueprint version
# Example output: go-blueprint v1.12.0
```
--------------------------------
### Docker Compose with MySQL
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/docker.md
This docker-compose.yml configuration sets up a Go application service and a MySQL database service. It demonstrates environment variable injection and health checks for the database.
```yaml
services:
app:
build:
context: .
dockerfile: Dockerfile
target: prod
restart: unless-stopped
ports:
- ${PORT}:${PORT}
environment:
APP_ENV: ${APP_ENV}
PORT: ${PORT}
BLUEPRINT_DB_HOST: ${BLUEPRINT_DB_HOST}
BLUEPRINT_DB_PORT: ${BLUEPRINT_DB_PORT}
BLUEPRINT_DB_DATABASE: ${BLUEPRINT_DB_DATABASE}
BLUEPRINT_DB_USERNAME: ${BLUEPRINT_DB_USERNAME}
BLUEPRINT_DB_PASSWORD: ${BLUEPRINT_DB_PASSWORD}
depends_on:
mysql_bp:
condition: service_healthy
networks:
- blueprint
mysql_bp:
image: mysql:latest
restart: unless-stopped
environment:
MYSQL_DATABASE: ${BLUEPRINT_DB_DATABASE}
MYSQL_USER: ${BLUEPRINT_DB_USERNAME}
MYSQL_PASSWORD: ${BLUEPRINT_DB_PASSWORD}
MYSQL_ROOT_PASSWORD: ${BLUEPRINT_DB_ROOT_PASSWORD}
ports:
- "${BLUEPRINT_DB_PORT}:3306"
volumes:
- mysql_volume_bp:/var/lib/mysql
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "${BLUEPRINT_DB_HOST}", "-u", "${BLUEPRINT_DB_USERNAME}", "--password=${BLUEPRINT_DB_PASSWORD}"]
interval: 5s
timeout: 5s
retries: 3
start_period: 15s
networks:
- blueprint
volumes:
mysql_volume_bp:
networks:
blueprint:
```
--------------------------------
### Check GOPATH
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/installation.md
Find out the correct GOPATH for your system. This is necessary for updating your PATH environment variable.
```bash
go env GOPATH
```
--------------------------------
### Enable Advanced Features with --advanced Flag
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/advanced-flag.md
Use the --advanced flag with the 'create' command to enable all integrated advanced features for your project. This is the primary method for activating enhanced functionality.
```bash
go-blueprint create --name --framework --driver --advanced
```
--------------------------------
### Hello World Endpoint
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/endpoints-test/server.md
This endpoint is used to test the basic 'Hello World' message from the server. If the server is running and healthy, it will return a JSON object with a 'message' field set to 'Hello World'.
```APIDOC
## GET /
### Description
Tests the Hello World endpoint to verify server health and basic functionality.
### Method
GET
### Endpoint
/
### Response
#### Success Response (200)
- **message** (string) - Indicates 'Hello World' if the server is healthy.
```
--------------------------------
### Enable All Advanced Features Non-Interactively
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/creating-project/project-init.md
Create a project with all advanced features enabled non-interactively by listing all desired `--feature` flags along with `--advanced` and other project configuration flags.
```bash
go-blueprint create --name my-project --framework chi --driver mysql --git commit --advanced --feature htmx --feature githubaction --feature websocket --feature tailwind --feature docker
```
--------------------------------
### Push Git Tag to Trigger Release
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/goreleaser.md
Push the newly created tag to your remote repository to initiate the GoReleaser process.
```bash
git push origin v1.0.0
```
--------------------------------
### Select Advanced Features Non-Interactively (GitHub Actions)
Source: https://context7.com/melkeydev/go-blueprint/llms.txt
Integrate GitHub Actions CI/CD into your project by using the --feature githubaction flag with --advanced. This generates configuration files for release and testing automation.
```bash
go-blueprint create --name my-app --framework chi --driver mysql --git commit --advanced --feature githubaction
```
--------------------------------
### Connect to Websocket Endpoint with Websocat
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/endpoints-test/websocket.md
Connect to the websocket endpoint using Websocat. Replace PORT with the actual port number your server is running on.
```bash
# Connect to the websocket endpoint
$ websocat ws://localhost:PORT/websocket
```
--------------------------------
### Server Run Logs (GIN Debug Mode)
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/endpoints-test/server.md
When running the application using 'make run', you will see debug logs in your terminal. These logs indicate the server's status, registered endpoints, and incoming requests.
```bash
make run
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
- using env: export GIN_MODE=release
- using code: gin.SetMode(gin.ReleaseMode)
[GIN-debug] GET / --> websocket-test/internal/server.(*Server).HelloWorldHandler-fm (3 handlers)
[GIN-debug] GET /health --> websocket-test/internal/server.(*Server).healthHandler-fm (3 handlers)
[GIN-debug] GET /websocket --> websocket-test/internal/server.(*Server).websocketHandler-fm (3 handlers)
[GIN] 2024/05/28 - 17:44:31 | 200 | 27.93µs | 127.0.0.1 | GET "/"
```
--------------------------------
### Sample Websocket Output
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/endpoints-test/websocket.md
This is sample output received after a successful connection to the websocket endpoint. It shows timestamp messages received from the server every 2 seconds.
```text
server timestamp: 1709046650354893857
server timestamp: 1709046652355956336
server timestamp: 1709046654357101642
server timestamp: 1709046656357202535
server timestamp: 1709046658358258120
server timestamp: 1709046660359338389
server timestamp: 1709046662360422533
server timestamp: 1709046664361194735
server timestamp: 1709046666362308678
server timestamp: 1709046668363390475
server timestamp: 1709046670364477838
server timestamp: 1709046672365193667
server timestamp: 1709046674366265199
server timestamp: 1709046676366564490
server timestamp: 1709046678367646090
server timestamp: 1709046680367851980
server timestamp: 1709046682368920527
```
--------------------------------
### Docker Compose with Database
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/react-vite.md
Defines services for a React Vite application, including the app itself, a frontend, and a PostgreSQL database. It configures environment variables, ports, volumes, and network settings.
```yaml
services:
app:
build:
context: .
dockerfile: Dockerfile
target: prod
restart: unless-stopped
ports:
- ${PORT}:${PORT}
environment:
APP_ENV: ${APP_ENV}
PORT: ${PORT}
BLUEPRINT_DB_HOST: ${BLUEPRINT_DB_HOST}
BLUEPRINT_DB_PORT: ${BLUEPRINT_DB_PORT}
BLUEPRINT_DB_DATABASE: ${BLUEPRINT_DB_DATABASE}
BLUEPRINT_DB_USERNAME: ${BLUEPRINT_DB_USERNAME}
BLUEPRINT_DB_PASSWORD: ${BLUEPRINT_DB_PASSWORD}
BLUEPRINT_DB_SCHEMA: ${BLUEPRINT_DB_SCHEMA}
depends_on:
psql_bp:
condition: service_healthy
networks:
- blueprint
frontend:
build:
context: .
dockerfile: Dockerfile
target: frontend
restart: unless-stopped
depends_on:
- app
ports:
- 5173:5173
networks:
- blueprint
psql_bp:
image: postgres:latest
restart: unless-stopped
environment:
POSTGRES_DB: ${BLUEPRINT_DB_DATABASE}
POSTGRES_USER: ${BLUEPRINT_DB_USERNAME}
POSTGRES_PASSWORD: ${BLUEPRINT_DB_PASSWORD}
ports:
- "${BLUEPRINT_DB_PORT}:5432"
volumes:
- psql_volume_bp:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "sh -c 'pg_isready -U ${BLUEPRINT_DB_USERNAME} -d ${BLUEPRINT_DB_DATABASE}'"]
interval: 5s
timeout: 5s
retries: 3
start_period: 15s
networks:
- blueprint
volumes:
psql_volume_bp:
networks:
blueprint:
```
--------------------------------
### Create Git Tag for Release
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/goreleaser.md
Create a new tag in your Git repository to mark a release. This is a prerequisite for triggering GoReleaser builds.
```bash
git tag v1.0.0
```
--------------------------------
### Enable All Advanced Features at Once
Source: https://github.com/melkeydev/go-blueprint/blob/main/README.md
Combine multiple --feature flags with the --advanced flag to enable all desired advanced features simultaneously.
```bash
go-blueprint create --name my-project --framework chi --driver mysql --advanced --feature htmx --feature githubaction --feature websocket --feature tailwind --feature docker --git commit --feature react
```
--------------------------------
### Enable Specific Advanced Features
Source: https://github.com/melkeydev/go-blueprint/blob/main/README.md
Use the --feature flag along with --advanced to enable individual advanced features.
```bash
go-blueprint create --advanced --feature htmx
```
```bash
go-blueprint create --advanced --feature githubaction
```
```bash
go-blueprint create --advanced --feature websocket
```
```bash
go-blueprint create --advanced --feature tailwind
```
```bash
go-blueprint create --advanced --feature docker
```
```bash
go-blueprint create --advanced --feature react
```
--------------------------------
### Project File Structure for Tailwind CSS
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/tailwind.md
This outlines the directory structure when Tailwind CSS is integrated, highlighting the location of input and output CSS files, and HTMX.
```bash
/ (Root)
├── cmd/
│ ├── api/
│ │ └── main.go
│ └── web/
│ ├── styles/
│ │ └── input.css
│ ├── assets/
│ │ ├── css/
│ │ │ └── output.css
│ │ └── js/
│ │ └── htmx.min.js
│ ├── base.templ
│ ├── base_templ.go
│ ├── efs.go
│ ├── hello.go
│ ├── hello.templ
│ └── hello_templ.go
├── internal/
│ └── server/
│ ├── routes.go
│ ├── routes_test.go
│ └── server.go
├── go.mod
├── go.sum
├── Makefile
└── README.md
```
--------------------------------
### WebSocket Handler Implementation
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/websocket.md
This Go code handles incoming WebSocket connections. It establishes a connection, sends timestamp messages every two seconds, and gracefully closes the connection when the server shuts down or an error occurs.
```go
func (s *Server) websocketHandler(c *gin.Context) {
w := c.Writer
r := c.Request
socket, err := websocket.Accept(w, r, nil)
if err != nil {
log.Printf("could not open websocket: %v", err)
_, _ = w.Write([]byte("could not open websocket"))
w.WriteHeader(http.StatusInternalServerError)
return
}
defer socket.Close(websocket.StatusGoingAway, "server closing websocket")
ctx := r.Context()
socketCtx := socket.CloseRead(ctx)
for {
payload := fmt.Sprintf("server timestamp: %d", time.Now().UnixNano())
err := socket.Write(socketCtx, websocket.MessageText, []byte(payload))
if err != nil {
break
}
time.Sleep(time.Second * 2)
}
}
```
--------------------------------
### Generate Templ Function Files
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/advanced-flag/htmx-templ.md
Run the templ generate command to compile .templ files into Go code. This command is typically automated by the Makefile.
```bash
templ generate
```
--------------------------------
### Check Current aio-max-nr Value
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/endpoints-test/scylladb.md
These commands help check the current value of the fs.aio-max-nr kernel parameter, which is important for ScyllaDB performance.
```sh
sysctl --all | grep --word-regexp -- 'aio-max-nr'
```
```sh
sysctl fs.aio-max-nr
```
```sh
cat /proc/sys/fs/aio-max-nr
```
--------------------------------
### Go Health Check Implementation for ScyllaDB
Source: https://github.com/melkeydev/go-blueprint/blob/main/docs/docs/endpoints-test/scylladb.md
This Go function checks ScyllaDB cluster health by executing queries against system keyspaces. It populates a map with status, messages, and cluster details. Ensure the ScyllaDB session is properly initialized.
```go
func (s *service) Health() map[string]string {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
stats := make(map[string]string)
// Check ScyllaDB health and populate the stats map
startedAt := time.Now()
// Execute a simple query to check connectivity
query := "SELECT now() FROM system.local"
iter := s.Session.Query(query).WithContext(ctx).Iter()
var currentTime time.Time
if !iter.Scan(¤tTime) {
if err := iter.Close(); err != nil {
stats["status"] = "down"
stats["message"] = fmt.Sprintf("Failed to execute query: %v", err)
return stats
}
}
if err := iter.Close(); err != nil {
stats["status"] = "down"
stats["message"] = fmt.Sprintf("Error during query execution: %v", err)
return stats
}
// ScyllaDB is up
stats["status"] = "up"
stats["message"] = "It's healthy"
stats["scylla_current_time"] = currentTime.String()
// Retrieve cluster information
// Get keyspace information
getKeyspacesQuery := "SELECT keyspace_name FROM system_schema.keyspaces"
keyspacesIterator := s.Session.Query(getKeyspacesQuery).Iter()
stats["scylla_keyspaces"] = strconv.Itoa(keyspacesIterator.NumRows())
if err := keyspacesIterator.Close(); err != nil {
log.Fatalf("Failed to close keyspaces iterator: %v", err)
}
// Get cluster information
var currentDatacenter string
var currentHostStatus bool
var clusterNodesUp uint
var clusterNodesDown uint
var clusterSize uint
clusterNodesIterator := s.Session.Query("SELECT dc, up FROM system.cluster_status").Iter()
for clusterNodesIterator.Scan(¤tDatacenter, ¤tHostStatus) {
clusterSize++
if currentHostStatus {
clusterNodesUp++
} else {
clusterNodesDown++
}
}
if err := clusterNodesIterator.Close(); err != nil {
log.Fatalf("Failed to close cluster nodes iterator: %v", err)
}
stats["scylla_cluster_size"] = strconv.Itoa(int(clusterSize))
stats["scylla_cluster_nodes_up"] = strconv.Itoa(int(clusterNodesUp))
stats["scylla_cluster_nodes_down"] = strconv.Itoa(int(clusterNodesDown))
stats["scylla_current_datacenter"] = currentDatacenter
// Calculate the time taken to perform the health check
stats["scylla_health_check_duration"] = time.Since(startedAt).String()
return stats
}
```