feat: setup monorepo infra — Go API + Vue 3 + PostgreSQL + Dockerfile Dokploy

Monorepo com apps/api (Go 1.23 + chi + pgx) e apps/web (Vue 3 + Vite + TypeScript).
Dockerfile multi-stage consolida tudo em imagem única (~25MB) para deploy no Dokploy.
Migrations rodando na inicialização; Vue embedado no binário Go via //go:embed.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
2026-05-26 20:06:37 -03:00
co-authored by Claude Sonnet 4.6
commit a3d8f363a5
25 changed files with 2131 additions and 0 deletions
+80
View File
@@ -0,0 +1,80 @@
package main
import (
"context"
"fmt"
"io/fs"
"log"
"net/http"
"os"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/joho/godotenv"
"financeiro-carvalho/internal/db"
"financeiro-carvalho/internal/handler"
"financeiro-carvalho/internal/migration"
"financeiro-carvalho/static"
)
func main() {
_ = godotenv.Load()
dsn := os.Getenv("DATABASE_URL")
if dsn == "" {
log.Fatal("DATABASE_URL is required")
}
ctx := context.Background()
pool, err := db.Connect(ctx, dsn)
if err != nil {
log.Fatalf("db connect: %v", err)
}
defer pool.Close()
if err := migration.Run(ctx, pool); err != nil {
log.Fatalf("migration: %v", err)
}
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Use(middleware.Recoverer)
r.Get("/health", handler.Health)
r.Route("/api", func(r chi.Router) {
// API routes added here as features are built
})
// Serve Vue SPA — non-API routes fall through to index.html
distFS, err := fs.Sub(static.FS, "dist")
if err != nil {
log.Fatalf("static embed sub: %v", err)
}
fileServer := http.FileServer(http.FS(distFS))
r.Get("/*", func(w http.ResponseWriter, req *http.Request) {
path := req.URL.Path[1:]
if _, statErr := fs.Stat(distFS, path); statErr != nil {
index, readErr := fs.ReadFile(distFS, "index.html")
if readErr != nil {
http.NotFound(w, req)
return
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Write(index)
return
}
fileServer.ServeHTTP(w, req)
})
fmt.Printf("server listening on :%s\n", port)
if err := http.ListenAndServe(":"+port, r); err != nil {
log.Fatal(err)
}
}