-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0917975
commit 1bbaa73
Showing
43 changed files
with
1,341 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
name: CI | ||
|
||
permissions: read-all | ||
|
||
on: | ||
push: | ||
paths: | ||
- cmd/** | ||
- internal/** | ||
- .github/workflows/ci.yml | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
format: | ||
name: Format | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: "1.23" | ||
- name: Get Go Cache Paths | ||
id: go-cache-paths | ||
run: | | ||
echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT | ||
echo "go-mod=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT | ||
- name: Install gofumpt | ||
run: go install mvdan.cc/gofumpt@latest | ||
- name: Go Build Cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ steps.go-cache-paths.outputs.go-build }} | ||
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} | ||
- name: Go Mod Cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ steps.go-cache-paths.outputs.go-mod }} | ||
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }} | ||
- name: Check Code Formatting | ||
run: | | ||
unformatted_files=$(gofumpt -l .) | ||
if [ -n "$unformatted_files" ]; then | ||
echo "Files not formatted:" | ||
echo "$unformatted_files" | ||
exit 1 | ||
fi | ||
lint: | ||
name: Lint | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
pull-requests: read | ||
checks: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: "1.23" | ||
- name: Get Go Cache Paths | ||
id: go-cache-paths | ||
run: | | ||
echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT | ||
echo "go-mod=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT | ||
- name: Go Build Cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ steps.go-cache-paths.outputs.go-build }} | ||
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} | ||
- name: Go Mod Cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ steps.go-cache-paths.outputs.go-mod }} | ||
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }} | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v5 | ||
with: | ||
version: latest | ||
working-directory: ./ | ||
args: --timeout=5m | ||
|
||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: "1.23" | ||
- name: Get Go Cache Paths | ||
id: go-cache-paths | ||
run: | | ||
echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT | ||
echo "go-mod=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT | ||
- name: Go Build Cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ steps.go-cache-paths.outputs.go-build }} | ||
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} | ||
- name: Go Mod Cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ steps.go-cache-paths.outputs.go-mod }} | ||
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }} | ||
- name: Run Tests with Coverage | ||
run: go test -v -race -coverprofile=coverage.txt ./... | ||
- name: Print Coverage | ||
run: go tool cover -func=coverage.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.DS_Store | ||
.env | ||
bin/ | ||
tmp/ | ||
htmx/ | ||
*_templ.go | ||
*_templ.txt | ||
cmd/server/deps | ||
cmd/server/public | ||
node_modules/ | ||
package-lock.json | ||
package.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
NODE_BIN := ./node_modules/.bin | ||
|
||
.PHONY:build | ||
build: gen-css gen-templ | ||
@go build -tags dev -o bin/roundest cmd/server/main.go | ||
|
||
.PHONY:build-prod | ||
build-prod: gen-css gen-templ | ||
@go build -tags prod -o bin/roundest cmd/server/main.go | ||
|
||
.PHONY:run | ||
run: build | ||
@./bin/roundest | ||
|
||
.PHONY: install | ||
install: install-templ gen-templ | ||
@go get ./... | ||
@go mod tidy | ||
@go mod download | ||
@mkdir -p cmd/server/deps | ||
@wget -q -O cmd/server/deps/htmx-2.0.3.min.js.gz https://unpkg.com/htmx.org@2.0.3/dist/htmx.min.js.gz | ||
@gunzip -f cmd/server/deps/htmx-2.0.3.min.js.gz | ||
@npm install -D daisyui@latest | ||
@npm install -D tailwindcss | ||
|
||
|
||
.PHONY: gen-css | ||
gen-css: | ||
@$(NODE_BIN)/tailwindcss build -i internal/views/css/app.css -o cmd/server/public/styles.css --minify | ||
|
||
.PHONY: watch-css | ||
watch-css: | ||
@$(NODE_BIN)/tailwindcss -i internal/views/css/app.css -o cmd/server/public/styles.css --minify --watch | ||
|
||
.PHONY: install-templ | ||
install-templ: | ||
@go install github.com/a-h/templ/cmd/templ@latest | ||
|
||
.PHONY: gen-templ | ||
gen-templ: | ||
@templ generate | ||
|
||
.PHONY: watch-templ | ||
watch-templ: | ||
@templ generate --watch --proxy=http://127.0.0.1:8000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"log/slog" | ||
|
||
"github.com/garrettladley/roundest/internal/services/pokeapi" | ||
"github.com/garrettladley/roundest/internal/settings" | ||
"github.com/garrettladley/roundest/internal/storage/postgres" | ||
"github.com/joho/godotenv" | ||
) | ||
|
||
func main() { | ||
if err := godotenv.Load(".env"); err != nil { | ||
log.Fatalf("Failed to load .env file: %v", err) | ||
} | ||
|
||
settings, err := settings.Load() | ||
if err != nil { | ||
log.Fatalf("Failed to load settings: %v", err) | ||
} | ||
|
||
db, err := postgres.New(postgres.From(settings.Database)) | ||
if err != nil { | ||
log.Fatalf("Failed to connect to database: %v", err) | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
if err := db.Schema(ctx); err != nil { | ||
log.Fatalf("Failed to create schema: %v", err) | ||
} | ||
|
||
pokemon, err := pokeapi.GetAllPokemon(ctx) | ||
if err != nil { | ||
log.Fatalf("Failed to get all pokemon: %v", err) | ||
} | ||
|
||
if err := db.Seed(ctx, pokemon); err != nil { | ||
log.Fatalf("Failed to seed database: %v", err) | ||
} | ||
|
||
slog.Info("Database seeded") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package main | ||
|
||
import ( | ||
"embed" | ||
"log" | ||
"log/slog" | ||
"net/http" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/garrettladley/roundest/internal/server" | ||
"github.com/garrettladley/roundest/internal/settings" | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/gofiber/fiber/v2/middleware/filesystem" | ||
"github.com/joho/godotenv" | ||
) | ||
|
||
func main() { | ||
if err := godotenv.Load(".env"); err != nil { | ||
log.Fatalf("Failed to load .env file: %v", err) | ||
} | ||
|
||
settings, err := settings.Load() | ||
if err != nil { | ||
log.Fatalf("Failed to load settings: %v", err) | ||
} | ||
|
||
app := server.Init(settings) | ||
|
||
static(app) | ||
|
||
go func() { | ||
if err := app.Listen(":" + settings.App.Port); err != nil { | ||
log.Fatalf("Failed to start server: %v", err) | ||
} | ||
}() | ||
|
||
quit := make(chan os.Signal, 1) | ||
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM) | ||
|
||
<-quit | ||
|
||
slog.Info("Shutting down server") | ||
if err := app.Shutdown(); err != nil { | ||
slog.Error("failed to shutdown server", "error", err) | ||
} | ||
|
||
slog.Info("Server shutdown") | ||
} | ||
|
||
//go:embed public | ||
var PublicFS embed.FS | ||
|
||
//go:embed deps | ||
Check failure on line 55 in cmd/server/main.go GitHub Actions / Lint
|
||
var DepsFS embed.FS | ||
|
||
func static(app *fiber.App) { | ||
app.Use("/public", filesystem.New(filesystem.Config{ | ||
Root: http.FS(PublicFS), | ||
PathPrefix: "public", | ||
Browse: true, | ||
})) | ||
app.Use("/deps", filesystem.New(filesystem.Config{ | ||
Root: http.FS(DepsFS), | ||
PathPrefix: "deps", | ||
Browse: true, | ||
})) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//go:build dev | ||
|
||
package main | ||
|
||
import ( | ||
"net/http" | ||
"os" | ||
) | ||
|
||
func public() http.Handler { | ||
return http.StripPrefix("/public/", http.FileServerFS(os.DirFS("public"))) | ||
} | ||
|
||
func deps() http.Handler { | ||
return http.StripPrefix("/deps/", http.FileServerFS(os.DirFS("deps"))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//go:build !dev | ||
|
||
package main | ||
|
||
import ( | ||
"embed" | ||
"net/http" | ||
) | ||
|
||
//go:embed public | ||
var publicFS embed.FS // nolint:unused | ||
|
||
// nolint:unused | ||
func public() http.Handler { | ||
return http.FileServerFS(publicFS) | ||
} | ||
|
||
//go:embed deps | ||
var depsFS embed.FS // nolint:unused | ||
|
||
// nolint:unused | ||
func deps() http.Handler { | ||
return http.FileServerFS(depsFS) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module github.com/garrettladley/roundest | ||
|
||
go 1.23.2 | ||
|
||
require github.com/gofiber/fiber/v2 v2.52.5 | ||
|
||
require ( | ||
github.com/philhofer/fwd v1.1.2 // indirect | ||
github.com/tinylib/msgp v1.1.8 // indirect | ||
) | ||
|
||
require ( | ||
github.com/a-h/templ v0.2.793 | ||
github.com/andybalholm/brotli v1.1.0 // indirect | ||
github.com/caarlos0/env/v11 v11.2.2 | ||
github.com/goccy/go-json v0.10.3 | ||
github.com/google/uuid v1.5.0 // indirect | ||
github.com/jmoiron/sqlx v1.4.0 | ||
github.com/joho/godotenv v1.5.1 | ||
github.com/klauspost/compress v1.17.0 // indirect | ||
github.com/lib/pq v1.10.9 | ||
github.com/mattn/go-colorable v0.1.13 // indirect | ||
github.com/mattn/go-isatty v0.0.20 // indirect | ||
github.com/mattn/go-runewidth v0.0.15 // indirect | ||
github.com/rivo/uniseg v0.2.0 // indirect | ||
github.com/valyala/bytebufferpool v1.0.0 // indirect | ||
github.com/valyala/fasthttp v1.51.0 // indirect | ||
github.com/valyala/tcplisten v1.0.0 // indirect | ||
golang.org/x/sys v0.23.0 // indirect | ||
) |
Oops, something went wrong.