diff --git a/.air.toml b/.air.toml index 4539103..05ddd60 100644 --- a/.air.toml +++ b/.air.toml @@ -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 = [] diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3f350c6..5cc46c2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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: @@ -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: @@ -43,5 +43,6 @@ jobs: - uses: WillAbides/setup-go-faster@v1.14.0 with: go-version: ${{ matrix.go }} + - run: "make test" \ No newline at end of file diff --git a/Makefile b/Makefile index d1ee529..f01419d 100644 --- a/Makefile +++ b/Makefile @@ -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 ./... \ No newline at end of file +.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 \ No newline at end of file diff --git a/README.md b/README.md index f6cb527..8efd5e6 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/cmd/main.go b/cmd/main.go index 0db45a4..d6a0f88 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -11,6 +11,7 @@ import ( "log/slog" "net/http" "os" + "os/exec" "os/signal" "syscall" "time" @@ -29,6 +30,8 @@ var Environment = "development" func init() { os.Setenv("env", Environment) + // run generate script + exec.Command("make", "tailwind-build").Run() } func main() { diff --git a/dev/Dockerfile b/dev/Dockerfile new file mode 100644 index 0000000..6084f05 --- /dev/null +++ b/dev/Dockerfile @@ -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"] diff --git a/dev/docker-compose.dev.yml b/dev/docker-compose.dev.yml new file mode 100644 index 0000000..436b534 --- /dev/null +++ b/dev/docker-compose.dev.yml @@ -0,0 +1,9 @@ +version: '3.8' +services: + app: + volumes: + - ..:/app + environment: + - ENVIRONMENT=development + ports: + - "4000:4000" \ No newline at end of file diff --git a/dev/docker-compose.yml b/dev/docker-compose.yml new file mode 100644 index 0000000..25ed554 --- /dev/null +++ b/dev/docker-compose.yml @@ -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 + diff --git a/dev/scripts/entrypoint.sh b/dev/scripts/entrypoint.sh new file mode 100644 index 0000000..c5b8509 --- /dev/null +++ b/dev/scripts/entrypoint.sh @@ -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 diff --git a/dev/scripts/generate.sh b/dev/scripts/generate.sh new file mode 100644 index 0000000..31e824b --- /dev/null +++ b/dev/scripts/generate.sh @@ -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 diff --git a/go.mod b/go.mod index eb3b8ad..4ff4f38 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 ) diff --git a/go.sum b/go.sum index cb0d75c..ca2066d 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/internal/middleware/middleware.go b/internal/middleware/middleware.go index a946af3..c1b79ce 100644 --- a/internal/middleware/middleware.go +++ b/internal/middleware/middleware.go @@ -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 } diff --git a/internal/templates/About_templ.go b/internal/templates/About_templ.go index ef9b8bf..57690bd 100644 --- a/internal/templates/About_templ.go +++ b/internal/templates/About_templ.go @@ -1,6 +1,6 @@ // Code generated by templ - DO NOT EDIT. -// templ: version: v0.2.663 +// templ: version: v0.2.543 package templates //lint:file-ignore SA4006 This context is only used if a nested component is present. diff --git a/internal/templates/Index_templ.go b/internal/templates/Index_templ.go index ae0cc55..6868d2b 100644 --- a/internal/templates/Index_templ.go +++ b/internal/templates/Index_templ.go @@ -1,6 +1,6 @@ // Code generated by templ - DO NOT EDIT. -// templ: version: v0.2.663 +// templ: version: v0.2.543 package templates //lint:file-ignore SA4006 This context is only used if a nested component is present. @@ -30,7 +30,7 @@ func Index(email string) templ.Component { var templ_7745c5c3_Var2 string templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(email) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/Index.templ`, Line: 5, Col: 16} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/Index.templ`, Line: 4, Col: 16} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { diff --git a/internal/templates/NotFound_templ.go b/internal/templates/NotFound_templ.go index 346d39f..1651d34 100644 --- a/internal/templates/NotFound_templ.go +++ b/internal/templates/NotFound_templ.go @@ -1,6 +1,6 @@ // Code generated by templ - DO NOT EDIT. -// templ: version: v0.2.663 +// templ: version: v0.2.543 package templates //lint:file-ignore SA4006 This context is only used if a nested component is present. diff --git a/internal/templates/layout.templ b/internal/templates/layout.templ index 2b2d7b8..33408c4 100644 --- a/internal/templates/layout.templ +++ b/internal/templates/layout.templ @@ -1,7 +1,6 @@ package templates import ( - "os" "goth/internal/middleware" ) @@ -12,11 +11,12 @@ templ header(title string) { - if os.Getenv("env") == "production" { - - } else { - - } + + // if os.Getenv("env") == "production" { + // + // } else { + // + // } } diff --git a/internal/templates/layout_templ.go b/internal/templates/layout_templ.go index f4aa9be..a3a1780 100644 --- a/internal/templates/layout_templ.go +++ b/internal/templates/layout_templ.go @@ -1,6 +1,6 @@ // Code generated by templ - DO NOT EDIT. -// templ: version: v0.2.663 +// templ: version: v0.2.543 package templates //lint:file-ignore SA4006 This context is only used if a nested component is present. @@ -12,7 +12,6 @@ import "bytes" import ( "goth/internal/middleware" - "os" ) func header(title string) templ.Component { @@ -35,7 +34,7 @@ func header(title string) templ.Component { var templ_7745c5c3_Var2 string templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(title) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/layout.templ`, Line: 10, Col: 16} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/layout.templ`, Line: 8, Col: 16} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { @@ -45,12 +44,7 @@ func header(title string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var3 string - templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(middleware.GetHtmxNonce(ctx)) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/layout.templ`, Line: 13, Col: 78} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(middleware.GetHtmxNonce(ctx))) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -58,57 +52,19 @@ func header(title string) templ.Component { if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var4 string - templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(middleware.GetResponseTargetsNonce(ctx)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(middleware.GetResponseTargetsNonce(ctx))) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/templates/layout.templ`, Line: 14, Col: 97} + return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(middleware.GetTwNonce(ctx))) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - if os.Getenv("env") == "production" { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - } else { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -127,9 +83,9 @@ func footer() templ.Component { defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var7 := templ.GetChildren(ctx) - if templ_7745c5c3_Var7 == nil { - templ_7745c5c3_Var7 = templ.NopComponent + templ_7745c5c3_Var3 := templ.GetChildren(ctx) + if templ_7745c5c3_Var3 == nil { + templ_7745c5c3_Var3 = templ.NopComponent } ctx = templ.ClearChildren(ctx) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("") @@ -151,12 +107,12 @@ func nav() templ.Component { defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) } ctx = templ.InitializeContext(ctx) - templ_7745c5c3_Var8 := templ.GetChildren(ctx) - if templ_7745c5c3_Var8 == nil { - templ_7745c5c3_Var8 = templ.NopComponent + templ_7745c5c3_Var4 := templ.GetChildren(ctx) + if templ_7745c5c3_Var4 == nil { + templ_7745c5c3_Var4 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("