Add debugger service

This commit is contained in:
Florian Hoss 2024-03-26 10:25:19 +01:00
parent 8d3b522ff0
commit 522e77766a
8 changed files with 68 additions and 23 deletions

13
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug golang",
"type": "go",
"request": "attach",
"mode": "remote",
"port": 4001,
"host": "127.0.0.1"
}
]
}

View file

@ -2,5 +2,6 @@
```sh ```sh
docker compose run --rm node yarn install docker compose run --rm node yarn install
docker compose up --build docker compose --profile dev up --build
docker compose --profile debug up --build
``` ```

View file

@ -4,7 +4,7 @@ import (
"github.com/logto-io/go/core" "github.com/logto-io/go/core"
) )
templ User(user *core.UserInfoResponse) { templ User(user core.UserInfoResponse) {
<div <div
x-data="{ x-data="{
open: false, open: false,

View file

@ -3,8 +3,8 @@ networks:
external: false external: false
services: services:
backend: backend:
profiles: [dev]
build: build:
context: . context: .
dockerfile_inline: | dockerfile_inline: |
@ -26,20 +26,54 @@ services:
command: air -c .air.toml command: air -c .air.toml
environment: environment:
- TZ=Europe/Berlin - TZ=Europe/Berlin
- PUBLIC_URL=http://localhost:4000 - PUBLIC_URL=${PUBLIC_URL}
- LOG_LEVEL=debug - TITLE=${TITLE}
- TITLE=DEV - APP_VERSION=${APP_VERSION}
- APP_VERSION=v0.0.1-DEV
- WEATHER_KEY=${WEATHER_KEY} - WEATHER_KEY=${WEATHER_KEY}
- LOGTO_ENDPOINT=${LOGTO_ENDPOINT} - LOGTO_ENDPOINT=${LOGTO_ENDPOINT}
- LOGTO_APP_ID=${LOGTO_APP_ID} - LOGTO_APP_ID=${LOGTO_APP_ID}
- LOGTO_APP_SECRET=${LOGTO_APP_SECRET} - LOGTO_APP_SECRET=${LOGTO_APP_SECRET}
- SESSION_KEY=super-secure - SESSION_KEY=${SESSION_KEY}
volumes: volumes:
- .:/app/ - .:/app/
ports: ports:
- 4000:4000 - 4000:4000
backend-debug:
profiles: [debug]
build:
context: .
dockerfile_inline: |
ARG V_GOLANG
FROM golang:${V_GOLANG}-alpine
RUN apk update && \
apk upgrade && \
apk add tzdata
RUN go install github.com/go-delve/delve/cmd/dlv@latest
WORKDIR /app
COPY go.mod .
COPY go.sum .
RUN go mod download
args:
- V_GOLANG=${V_GOLANG}
command: /app/scripts/debug.sh
environment:
- TZ=Europe/Berlin
- PUBLIC_URL=${PUBLIC_URL}
- APP_VERSION=${APP_VERSION}
- WEATHER_KEY=${WEATHER_KEY}
- LOGTO_ENDPOINT=${LOGTO_ENDPOINT}
- LOGTO_APP_ID=${LOGTO_APP_ID}
- LOGTO_APP_SECRET=${LOGTO_APP_SECRET}
- SESSION_KEY=${SESSION_KEY}
volumes:
- .:/app/
ports:
- 4000:4000
- 4001:4001
templ: templ:
profiles: [dev] profiles: [dev]
build: build:

View file

@ -2,6 +2,7 @@ package handlers
import ( import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/logto-io/go/client"
"gitlab.unjx.de/flohoss/godash/internal/env" "gitlab.unjx.de/flohoss/godash/internal/env"
"gitlab.unjx.de/flohoss/godash/services" "gitlab.unjx.de/flohoss/godash/services"
"gitlab.unjx.de/flohoss/godash/views/home" "gitlab.unjx.de/flohoss/godash/views/home"
@ -43,7 +44,12 @@ func (bh *AppHandler) appHandler(c echo.Context) error {
staticSystem := bh.systemService.GetStaticInformation() staticSystem := bh.systemService.GetStaticInformation()
liveSystem := bh.systemService.GetLiveInformation() liveSystem := bh.systemService.GetLiveInformation()
weather := bh.weatherService.GetCurrentWeather() weather := bh.weatherService.GetCurrentWeather()
user := bh.authHandler.GetUserInfo()
logtoClient := client.NewLogtoClient(
bh.authHandler.logtoConfig,
NewSessionStorage(c),
)
user, _ := logtoClient.FetchUserInfo()
titlePage := bh.env.Title titlePage := bh.env.Title

View file

@ -6,7 +6,6 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/logto-io/go/client" "github.com/logto-io/go/client"
"github.com/logto-io/go/core"
"gitlab.unjx.de/flohoss/godash/internal/env" "gitlab.unjx.de/flohoss/godash/internal/env"
) )
@ -24,11 +23,6 @@ func NewAuthHandler(env *env.Config) *AuthHandler {
type AuthHandler struct { type AuthHandler struct {
env *env.Config env *env.Config
logtoConfig *client.LogtoConfig logtoConfig *client.LogtoConfig
userInfo *core.UserInfoResponse
}
func (authHandler *AuthHandler) GetUserInfo() *core.UserInfoResponse {
return authHandler.userInfo
} }
func (authHandler *AuthHandler) logtoMiddleware(next echo.HandlerFunc) echo.HandlerFunc { func (authHandler *AuthHandler) logtoMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
@ -40,13 +34,6 @@ func (authHandler *AuthHandler) logtoMiddleware(next echo.HandlerFunc) echo.Hand
if !logtoClient.IsAuthenticated() { if !logtoClient.IsAuthenticated() {
return c.Redirect(http.StatusTemporaryRedirect, "/sign-in") return c.Redirect(http.StatusTemporaryRedirect, "/sign-in")
} }
if authHandler.userInfo == nil {
info, err := logtoClient.FetchUserInfo()
if err != nil {
return echo.ErrInternalServerError
}
authHandler.userInfo = &info
}
return next(c) return next(c)
} }
} }

4
scripts/debug.sh Executable file
View file

@ -0,0 +1,4 @@
#!/bin/sh
go build -gcflags="all=-N -l" -o /tmp/app
dlv --listen=:4001 --headless=true --api-version=2 --accept-multiclient exec /tmp/app

View file

@ -8,7 +8,7 @@ import (
"github.com/logto-io/go/core" "github.com/logto-io/go/core"
) )
templ Home(title string, user *core.UserInfoResponse, bookmarks *services.Bookmarks, static *services.StaticInformation, live *services.LiveInformation, weather *services.OpenWeather) { templ Home(title string, user core.UserInfoResponse, bookmarks *services.Bookmarks, static *services.StaticInformation, live *services.LiveInformation, weather *services.OpenWeather) {
<section class="grid gap-10"> <section class="grid gap-10">
<div class="flex w-full justify-between items-center"> <div class="flex w-full justify-between items-center">
@components.Weather(weather) @components.Weather(weather)