diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 00000000..e69de29b diff --git a/404.html b/404.html new file mode 100644 index 00000000..011293ee --- /dev/null +++ b/404.html @@ -0,0 +1,1042 @@ + + + +
+ + + + + + + + + + + + + + + + +The --advanced
flag in Blueprint serves as a switch to enable additional features during project creation. It is applied with the create
command and unlocks the following features:
HTMX Support using Templ: +Enables the integration of HTMX support for dynamic web pages using Templ.
+CI/CD Workflow Setup using GitHub Actions: +Automates the setup of a CI/CD workflow using GitHub Actions.
+Websocket Support: +WebSocket endpoint that sends continuous data streams through the WS protocol.
+Tailwind: +Adds Tailwind CSS support to the project.
+Docker: +Docker configuration for go project.
+React: +Frontend written in TypeScript, including an example fetch request to the backend.
+To utilize the --advanced
flag, use the following command:
go-blueprint create --name <project_name> --framework <selected_framework> --driver <selected_driver> --advanced
+
+By including the --advanced
flag, users can choose one or all of the advanced features. The flag enhances the simplicity of Blueprint while offering flexibility for users who require additional functionality.
To recreate the project using the same configuration semi-interactively, use the following command:
+go-blueprint create --name my-project --framework chi --driver mysql --advanced
+
+Non-Interactive Setup is also possible:
+go-blueprint create --name my-project --framework chi --driver mysql --advanced --feature htmx --feature githubaction --feature websocket --feature tailwind
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ The Docker advanced flag provides the app's Dockerfile configuration and creates or updates the docker-compose.yml file, which is generated if a DB driver is used. +The Dockerfile includes a two-stage build, and the final config depends on the use of advanced features. In the end, you will have a smaller image without unnecessary build dependencies.
+FROM golang:1.23-alpine AS build
+
+RUN apk add --no-cache curl
+
+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 -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"]
+
+Docker config if React flag is used:
+FROM golang:1.23-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"]
+
+Docker and docker-compose.yml pull environment variables from the .env file.
+Example if the Docker flag is used with the MySQL DB driver:
+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:
+
+If you are testing more than one framework locally, be aware of Docker leftovers such as volumes.
+For proper cleaning and building, use docker compose down --volumes
and docker compose up --build
.
or
+docker compose build --no-cache && docker compose up
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Release process for Go projects, providing extensive customization options through its configuration file, .goreleaser.yml
. By default, it ensures dependency cleanliness, builds binaries for various platforms and architectures, facilitates pre-release creation, and organizes binary packaging into archives with naming schemes.
For comprehensive insights into customization possibilities, refer to the GoReleaser documentation.
+To initiate release builds with GoReleaser, you need to follow these steps:
+git tag v1.0.0
+
+git push origin v1.0.0
+
+Following these steps ensures proper tagging of your project, prompting GoReleaser to execute configured releases. This approach simplifies release management and automates artifact distribution.
+The go-test.yml
file defines a GitHub Actions workflow for continuous integration (CI) of Go projects within a GitHub repository.
The job outlined in this workflow includes the following steps:
+Checkout: + Fetches the project's codebase from the repository.
+Go Setup: + Configures the Go environment with version 1.21.x.
+Build and Test:
+ Builds the project using go build
and runs tests across all packages (./...
) using go test
.
This workflow serves to automate the testing process of a Go project within a GitHub repository, ensuring code quality and reliability with each commit and pull request.
+ + + + + + + + + + + + + +The WEB directory contains the web-related components and assets for the project. It leverages htmx and templ in Go for dynamic web content generation.
+web/
+│
+│
+├── assets/
+│ └── js/
+│ └── htmx.min.js # htmx library for dynamic HTML content
+│
+├── base.templ # Base template for HTML structure
+├── base_templ.go # Generated Go code for base template
+├── efs.go # Embeds static files into the Go binary
+│
+├── hello.go # Handler for the Hello Web functionality
+├── hello.templ # Template for rendering the Hello form and post data
+└── hello_templ.go # Generated Go code for hello template
+
+cd my-project
+
+go install github.com/a-h/templ/cmd/templ@latest
+
+templ generate
+
+make run
+
+Automates templ with Makefile entries, which are automatically created if the htmx advanced flag is used. +It detects if templ is installed or not and generates templates with the make build command. +Both Windows and Unix-like OS are supported.
+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
+
+Templates are generated using the templ generate
command after project creation. These templates are then compiled into Go code for efficient execution.
You can test HTMX functionality on localhost:PORT/web
endpoint.
This template provides a minimal setup for getting React working with Vite for the frontend and go on the backend. It allows you to easily integrate React with Tailwind CSS and Vite for fast development.
+The React advanced flag can be combined with the Tailwind flag for enhanced styling capabilities.
+/ (Root)
+├── frontend/ # React advanced flag. Excludes HTMX.
+│ ├── .env # Frontend environment configuration
+│ ├── node_modules/ # Node dependencies.
+│ ├── public/
+│ │ ├── index.html
+│ │ └── favicon.ico
+│ ├── src/ # React source files.
+│ │ ├── App.tsx # Main React component.
+│ │ ├── assets/ # React assets directory
+│ │ │ └── logo.svg
+│ │ ├── components/ # React components directory.
+│ │ │ ├── Header.tsx
+│ │ │ └── Footer.tsx
+│ │ ├── styles/ # CSS/SCSS styles directory.
+│ │ │ └── global.css
+│ │ └── index.tsx # Main entry point for React
+│ ├── eslint.config.js # ESLint configuration file.
+│ ├── index.html # Base HTML template.
+│ ├── package.json # Node.js package configuration.
+│ ├── package-lock.json # Lock file for Node.js dependencies.
+│ ├── README.md # README file for the React project.
+│ ├── tsconfig.app.json # TypeScript configuration for the app.
+│ ├── tsconfig.json # Root TypeScript configuration.
+│ ├── tsconfig.node.json # TypeScript configuration for Node.js.
+│ └── vite.config.ts # Vite configuration file.
+
+frontend
directory:
+ First, navigate to the frontend
directory where the React project resides.cd frontend
+
+npm install
+
+npm run dev
+
+You should now be able to access the React application by opening a browser and navigating to http://localhost:5173
.
You can extend the vite.config.ts
to include additional configurations as needed, such as adding plugins for optimizing the build process, enabling TypeScript support, or configuring Tailwind CSS.
The make run target will start the Go server in the backend, install frontend dependencies, and run the Vite development server for the frontend.
+run:
+ @go run cmd/api/main.go &
+ @npm install --prefix ./frontend
+ @npm run dev --prefix ./frontend
+
+After running this command, you can verify the connection between the frontend and backend by checking the console. You can also fetch data from the backend to test the integration.
+ +Combine React advanced flag with Docker flag to get Docker and docker-compose configuration and run them with:
+make docker-run
+
+FROM golang:1.23-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"]
+
+services:
+ app:
+ build:
+ context: .
+ dockerfile: Dockerfile
+ target: prod
+ restart: unless-stopped
+ ports:
+ - ${PORT}:${PORT}
+ environment:
+ APP_ENV: ${APP_ENV}
+ PORT: ${PORT}
+ frontend:
+ build:
+ context: .
+ dockerfile: Dockerfile
+ target: frontend
+ restart: unless-stopped
+ ports:
+ - 5173:5173
+ depends_on:
+ - app
+
+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:
+
+The VITE_PORT
in .env refers PORT
from .env in project root ( for backend ). If value of PORT
is changed than VITE_PORT
must also be changed so that requests to backend work fine and have no conflicts.
Tailwind is closely coupled with the advanced HTMX flag, and HTMX will be automatically used if you select Tailwind in your project.
+We do not introduce outside dependencies automatically, and you need compile output.css (file is empty by default) with the Tailwind CLI tool.
+The project tree would look like this:
+/ (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
+└── tailwind.config.js
+
+The The idea is to avoid using Node.js and npm to build output.css.
+The Makefile will have entries for downloading and compiling CSS. It will automatically detect the OS and download the latest release from the official repository.
+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
+
+By default, simple CSS examples are included in the codebase.
+Update base.templ and hello.templ, then rerun templ generate to see the changes at the localhost:PORT/web
endpoint.
A /websocket
endpoint is added in routes.go
to facilitate websocket connections. Upon accessing this endpoint, the server establishes a websocket connection and begins transmitting timestamp messages at 2-second intervals. WS is utilized across all Go-blueprint supported frameworks. This simple implementation showcases how flexible project is.
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)
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {"use strict";/*!
+ * escape-html
+ * Copyright(c) 2012-2013 TJ Holowaychuk
+ * Copyright(c) 2015 Andreas Lubbe
+ * Copyright(c) 2015 Tiancheng "Timothy" Gu
+ * MIT Licensed
+ */var Va=/["'&<>]/;qn.exports=za;function za(e){var t=""+e,r=Va.exec(t);if(!r)return t;var o,n="",i=0,s=0;for(i=r.index;i