Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tmp_dir = "tmp"
[build]
args_bin = []
bin = "./tmp/main"
cmd = "templ generate && go build -o tmp/main ./cmd"
cmd = "go build -o tmp/main ./cmd"
delay = 0
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: false
matrix:
os: ["windows-latest", "ubuntu-latest", "macOS-latest"]
go: ["1.22.x"]
go: ["1.23.x"]
dir: ["./"]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -33,7 +33,7 @@ jobs:
fail-fast: false
matrix:
os: ["windows-latest", "ubuntu-latest", "macOS-latest"]
go: ["1.22.x"]
go: ["1.23.x"]
dir: ["./"]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -43,5 +43,6 @@ jobs:
- uses: WillAbides/[email protected]
with:
go-version: ${{ matrix.go }}

- run: "make test"

56 changes: 39 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,37 +1,59 @@
APP_NAME ?= app

.PHONY: vet
vet:
go vet ./...

.PHONY: staticcheck
staticcheck:
staticcheck ./...

.PHONY: test
test:
go test -race -v -timeout 30s ./...

.PHONY: tailwind-watch
tailwind-watch:
./tailwindcss -i ./static/css/input.css -o ./static/css/style.css --watch
tailwindcss -i ./static/css/input.css -o ./static/css/style.css --watch

.PHONY: tailwind-build
tailwind-build:
./tailwindcss -i ./static/css/input.css -o ./static/css/style.min.css --minify

.PHONY: templ-generate
templ-generate:
templ generate
tailwindcss -i ./static/css/input.css -o ./static/css/style.min.css --minify

.PHONY: templ-watch
templ-watch:
templ generate --watch

.PHONY: templ-generate
templ-generate:
templ generate

.PHONY: dev
dev:
go build -o ./tmp/$(APP_NAME) ./cmd/$(APP_NAME)/main.go && air
go build -o ./tmp/main ./cmd/main.go && air

.PHONY: build
build:
make tailwind-build
make templ-generate
go build -ldflags "-X main.Environment=production" -o ./bin/$(APP_NAME) ./cmd/$(APP_NAME)/main.go
go build -ldflags "-X main.Environment=production" -o ./bin/$(APP_NAME) ./cmd/main.go

.PHONY: vet
vet:
go vet ./...
.PHONY: docker-build
docker-build:
docker-compose -f ./dev/docker-compose.yml build

.PHONY: staticcheck
staticcheck:
staticcheck ./...
.PHONY: docker-up
docker-up:
docker-compose -f ./dev/docker-compose.yml up

.PHONY: test
test:
go test -race -v -timeout 30s ./...
.PHONY: docker-dev
docker-dev:
docker-compose -f ./dev/docker-compose.yml -f ./dev/docker-compose.dev.yml up

.PHONY: docker-down
docker-down:
docker-compose -f ./dev/docker-compose.yml down

.PHONY: docker-clean
docker-clean:
docker-compose -f ./dev/docker-compose.yml down -v --rmi all
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ https://github.com/cosmtrek/air
## Makefile
This Makefile is designed to simplify common development tasks for your project. It includes targets for building your Go application, watching and building Tailwind CSS, generating templates, and running your development server using Air.


## Development
`make docker-dev` will start everything in watch mode inside a Docker container.

### Targets:

```bash
make tailwind-watch
```
Expand Down
3 changes: 3 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"log/slog"
"net/http"
"os"
"os/exec"
"os/signal"
"syscall"
"time"
Expand All @@ -29,6 +30,8 @@ var Environment = "development"

func init() {
os.Setenv("env", Environment)
// run generate script
exec.Command("make", "tailwind-build").Run()
}

func main() {
Expand Down
16 changes: 16 additions & 0 deletions dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM golang:1.23-alpine
WORKDIR /app

RUN apk add --no-cache make gcc g++ curl

RUN go install github.com/a-h/templ/cmd/templ@latest && \
go install github.com/air-verse/air@latest

RUN curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64 && \
chmod +x tailwindcss-linux-x64 && \
mv tailwindcss-linux-x64 /usr/local/bin/tailwindcss

COPY dev/scripts/entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh

ENTRYPOINT ["entrypoint.sh"]
9 changes: 9 additions & 0 deletions dev/docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '3.8'
services:
app:
volumes:
- ..:/app
environment:
- ENVIRONMENT=development
ports:
- "4000:4000"
12 changes: 12 additions & 0 deletions dev/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# ./dev/docker-compose.yml (Base configuration)
version: '3.8'
services:
app:
build:
context: ..
dockerfile: dev/Dockerfile
ports:
- "4000:4000"
environment:
- ENVIRONMENT=production

20 changes: 20 additions & 0 deletions dev/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh
set -e # Exit on error

cd /app

if [ "$ENVIRONMENT" = "development" ]; then
echo "Starting in development mode..."

echo "Starting dev server..."
air &

echo "Starting templ watch..."
make templ-watch &

wait
else
echo "Starting in production mode..."
make build
./bin/app
fi
12 changes: 12 additions & 0 deletions dev/scripts/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
set -e # Exit on error

cd /app

if [ "$ENVIRONMENT" = "development" ]; then
make tailwind-watch
make templ-watch
else
make tailwind-build
make templ-generate
fi
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module goth
go 1.22

require (
github.com/a-h/templ v0.2.543
github.com/a-h/templ v0.2.793
github.com/go-chi/chi/v5 v5.0.11
github.com/google/uuid v1.6.0
github.com/kelseyhightower/envconfig v1.4.0
Expand All @@ -20,6 +20,6 @@ require (
github.com/mattn/go-sqlite3 v1.14.22 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/sys v0.23.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/a-h/templ v0.2.543 h1:8YyLvyUtf0/IE2nIwZ62Z/m2o2NqwhnMynzOL78Lzbk=
github.com/a-h/templ v0.2.543/go.mod h1:jP908DQCwI08IrnTalhzSEH9WJqG/Q94+EODQcJGFUA=
github.com/a-h/templ v0.2.793 h1:Io+/ocnfGWYO4VHdR0zBbf39PQlnzVCVVD+wEEs6/qY=
github.com/a-h/templ v0.2.793/go.mod h1:lq48JXoUvuQrU0VThrK31yFwdRjTCnIE5bcPCM9IP1w=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-chi/chi/v5 v5.0.11 h1:BnpYbFZ3T3S1WMpD79r7R5ThWX40TaFB7L31Y8xqSwA=
Expand All @@ -26,6 +28,8 @@ golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
1 change: 0 additions & 1 deletion internal/middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func (m *AuthMiddleware) AddUserToContext(next http.Handler) http.Handler {
sessionCookie, err := r.Cookie(m.sessionCookieName)

if err != nil {
fmt.Println("error getting session cookie", err)
next.ServeHTTP(w, r)
return
}
Expand Down
2 changes: 1 addition & 1 deletion internal/templates/About_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/templates/Index_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/templates/NotFound_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions internal/templates/layout.templ
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package templates

import (
"os"
"goth/internal/middleware"
)

Expand All @@ -12,11 +11,12 @@ templ header(title string) {
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<script src="static/script/htmx.min.js" nonce={ middleware.GetHtmxNonce(ctx) }></script>
<script src="static/script/response-targets.js" nonce={ middleware.GetResponseTargetsNonce(ctx) }></script>
if os.Getenv("env") == "production" {
<link rel="stylesheet" href="static/css/style.min.css" nonce={ middleware.GetTwNonce(ctx) }/>
} else {
<link rel="stylesheet" href="static/css/style.css" nonce={ middleware.GetTwNonce(ctx) }/>
}
<link rel="stylesheet" href="static/css/style.min.css" nonce={ middleware.GetTwNonce(ctx) }/>
// if os.Getenv("env") == "production" {
// <link rel="stylesheet" href="static/css/style.min.css" nonce={ middleware.GetTwNonce(ctx) }/>
// } else {
// <link rel="stylesheet" href="static/css/style.css" nonce={ middleware.GetTwNonce(ctx) }/>
// }
</head>
}

Expand Down
Loading