Skip to content

Commit 6481ebe

Browse files
committed
import and git impl
1 parent 9e33987 commit 6481ebe

26 files changed

+4410
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
go-blueprint
2+
main
3+
24
site
5+
6+
*templ.go
7+
output.css
8+
tailwindcss

blueprint-ui/.air.toml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
root = "."
2+
testdata_dir = "testdata"
3+
tmp_dir = "tmp"
4+
5+
[build]
6+
args_bin = []
7+
bin = "./main"
8+
cmd = "make build"
9+
delay = 1000
10+
exclude_dir = ["assets", "tmp", "vendor", "testdata", "node_modules"]
11+
exclude_file = []
12+
exclude_regex = ["_test.go", ".*_templ.go"]
13+
exclude_unchanged = false
14+
follow_symlink = false
15+
full_bin = ""
16+
include_dir = []
17+
include_ext = ["go", "tpl", "tmpl", "html", "templ"]
18+
include_file = []
19+
kill_delay = "0s"
20+
log = "build-errors.log"
21+
poll = false
22+
poll_interval = 0
23+
post_cmd = []
24+
pre_cmd = []
25+
rerun = false
26+
rerun_delay = 500
27+
send_interrupt = false
28+
stop_on_error = false
29+
30+
[color]
31+
app = ""
32+
build = "yellow"
33+
main = "magenta"
34+
runner = "green"
35+
watcher = "cyan"
36+
37+
[log]
38+
main_only = false
39+
time = false
40+
41+
[misc]
42+
clean_on_exit = false
43+
44+
[screen]
45+
clear_on_rebuild = false
46+
keep_scroll = true

blueprint-ui/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
PORT=8080
2+
APP_ENV=local

blueprint-ui/Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM golang:1.23-alpine AS build
2+
3+
RUN apk add --no-cache curl
4+
5+
WORKDIR /app
6+
7+
COPY go.mod go.sum ./
8+
RUN go mod download
9+
10+
COPY . .
11+
RUN go install github.com/a-h/templ/cmd/templ@latest && \
12+
templ generate && \
13+
curl -sL https://github.com/tailwindlabs/tailwindcss/releases/download/v3.4.10/tailwindcss-linux-x64 -o tailwindcss && \
14+
chmod +x tailwindcss && \
15+
./tailwindcss -i cmd/web/styles/input.css -o cmd/web/assets/css/output.css
16+
17+
RUN go build -o main cmd/api/main.go
18+
19+
FROM alpine:3.20.1 AS prod
20+
WORKDIR /app
21+
COPY --from=build /app/main /app/main
22+
EXPOSE ${PORT}
23+
CMD ["./main"]

blueprint-ui/Makefile

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Simple Makefile for a Go project
2+
3+
# Build the application
4+
all: build
5+
templ-install:
6+
@if ! command -v templ > /dev/null; then \
7+
read -p "Go's 'templ' is not installed on your machine. Do you want to install it? [Y/n] " choice; \
8+
if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \
9+
go install github.com/a-h/templ/cmd/templ@latest; \
10+
if [ ! -x "$$(command -v templ)" ]; then \
11+
echo "templ installation failed. Exiting..."; \
12+
exit 1; \
13+
fi; \
14+
else \
15+
echo "You chose not to install templ. Exiting..."; \
16+
exit 1; \
17+
fi; \
18+
fi
19+
tailwind-install:
20+
@if [ ! -f tailwindcss ]; then curl -sL https://github.com/tailwindlabs/tailwindcss/releases/download/v3.4.10/tailwindcss-linux-x64 -o tailwindcss; fi
21+
22+
@chmod +x tailwindcss
23+
24+
build: tailwind-install templ-install
25+
@echo "Building..."
26+
@templ generate
27+
@./tailwindcss -i cmd/web/styles/input.css -o cmd/web/assets/css/output.css
28+
@go build -o main cmd/api/main.go
29+
30+
# Run the application
31+
run: build
32+
@echo "Starting server..."
33+
@./main
34+
# Create DB container
35+
docker-run:
36+
@if docker compose up --build 2>/dev/null; then \
37+
: ; \
38+
else \
39+
echo "Falling back to Docker Compose V1"; \
40+
docker-compose up --build; \
41+
fi
42+
43+
# Shutdown DB container
44+
docker-down:
45+
@if docker compose down 2>/dev/null; then \
46+
: ; \
47+
else \
48+
echo "Falling back to Docker Compose V1"; \
49+
docker-compose down; \
50+
fi
51+
52+
# Clean the binary
53+
clean:
54+
@echo "Cleaning..."
55+
@pkill main || true
56+
@rm -f main
57+
58+
# Live Reload
59+
watch:
60+
@if command -v air > /dev/null; then \
61+
air; \
62+
echo "Watching...";\
63+
else \
64+
read -p "Go's 'air' is not installed on your machine. Do you want to install it? [Y/n] " choice; \
65+
if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \
66+
go install github.com/air-verse/air@latest; \
67+
air; \
68+
echo "Watching...";\
69+
else \
70+
echo "You chose not to install air. Exiting..."; \
71+
exit 1; \
72+
fi; \
73+
fi
74+
75+
.PHONY: all build run clean watch tailwind-install templ-install

blueprint-ui/cmd/api/main.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"log"
7+
"net/http"
8+
"os/signal"
9+
"syscall"
10+
"time"
11+
12+
"bluepront-ui/internal/server"
13+
)
14+
15+
func gracefulShutdown(apiServer *http.Server, done chan bool) {
16+
// Create context that listens for the interrupt signal from the OS.
17+
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
18+
defer stop()
19+
20+
// Listen for the interrupt signal.
21+
<-ctx.Done()
22+
23+
log.Println("shutting down gracefully, press Ctrl+C again to force")
24+
25+
// The context is used to inform the server it has 5 seconds to finish
26+
// the request it is currently handling
27+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
28+
defer cancel()
29+
if err := apiServer.Shutdown(ctx); err != nil {
30+
log.Printf("Server forced to shutdown with error: %v", err)
31+
}
32+
33+
log.Println("Server exiting")
34+
35+
// Notify the main goroutine that the shutdown is complete
36+
done <- true
37+
}
38+
39+
func main() {
40+
41+
server := server.NewServer()
42+
43+
// Create a done channel to signal when the shutdown is complete
44+
done := make(chan bool, 1)
45+
46+
// Run graceful shutdown in a separate goroutine
47+
go gracefulShutdown(server, done)
48+
49+
err := server.ListenAndServe()
50+
if err != nil && err != http.ErrServerClosed {
51+
panic(fmt.Sprintf("http server error: %s", err))
52+
}
53+
54+
// Wait for the graceful shutdown to complete
55+
<-done
56+
log.Println("Graceful shutdown complete.")
57+
}

0 commit comments

Comments
 (0)