logger
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 3m33s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 3m33s
This commit is contained in:
parent
4565a728a5
commit
730f411494
@ -98,11 +98,17 @@
|
|||||||
- `emit_interface: true` (generated `Querier` interface)
|
- `emit_interface: true` (generated `Querier` interface)
|
||||||
- `emit_json_tags: false` (can be revisited if API structs are returned directly)
|
- `emit_json_tags: false` (can be revisited if API structs are returned directly)
|
||||||
- Initial queries implemented for users: `GetUser`, `CreateUser`, `DeleteUser`
|
- Initial queries implemented for users: `GetUser`, `CreateUser`, `DeleteUser`
|
||||||
- **Goose startup migrations** have been wired into `cmd/api/main.go`, utilizing the `embed.FS` strategy and logging via Zap adapter.
|
- **Goose startup migrations** wired into `db.ProvidePool`, utilizing the `embed.FS` strategy.
|
||||||
- DB pool is successfully wired in `cmd/api`.
|
- **fx DI fully implemented.** All dependencies are provided via `fx.Provide` constructors:
|
||||||
- Environment-aware Zap logger is configured (development vs production).
|
- `config.Provide` → `*Config`
|
||||||
- **fx DI wiring** is being introduced to replace manual dependency injection in `main.go`. HTTP layer will use domain handlers structured by route hierarchy (`internal/http/api/...`).
|
- `logger.NewFromConfig` → `*zap.SugaredLogger`
|
||||||
- **Next Planned:** Implement fx providers for Gin server and DB pool, build `internal/http/server.go`, `internal/http/router.go`, and initial domain handlers (`health`, `auth`).
|
- `db.ProvidePool` → `*pgxpool.Pool` (lifecycle hooks for graceful shutdown)
|
||||||
|
- `http.NewServer` → `*gin.Engine` (lifecycle hooks for startup/shutdown)
|
||||||
|
- `health.NewHandler` → `*health.Handler`
|
||||||
|
- **HTTP route hierarchy** via `internal/http/router.go` (`GlueRoutes`):
|
||||||
|
- `GET /api/health/live` - process is alive
|
||||||
|
- `GET /api/health/ready` - DB ping succeeds
|
||||||
|
- **Next Planned:** Auth handler (`/api/auth/login`, `/api/auth/register`), JWT middleware, service layer.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@ -7,13 +7,15 @@ import (
|
|||||||
"git.kanopo.dev/rhythm/rhythm-backend/internal/http/api/health"
|
"git.kanopo.dev/rhythm/rhythm-backend/internal/http/api/health"
|
||||||
"git.kanopo.dev/rhythm/rhythm-backend/internal/logger"
|
"git.kanopo.dev/rhythm/rhythm-backend/internal/logger"
|
||||||
"go.uber.org/fx"
|
"go.uber.org/fx"
|
||||||
|
"go.uber.org/fx/fxevent"
|
||||||
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fx.New(
|
fx.New(
|
||||||
fx.Provide(
|
fx.Provide(
|
||||||
config.Provide,
|
config.Provide,
|
||||||
logger.NewFromConfig,
|
logger.ProvideLogger,
|
||||||
db.ProvidePool,
|
db.ProvidePool,
|
||||||
http.NewServer,
|
http.NewServer,
|
||||||
health.NewHandler,
|
health.NewHandler,
|
||||||
@ -21,5 +23,8 @@ func main() {
|
|||||||
fx.Invoke(
|
fx.Invoke(
|
||||||
http.GlueRoutes,
|
http.GlueRoutes,
|
||||||
),
|
),
|
||||||
|
fx.WithLogger(func(logger *zap.Logger) fxevent.Logger {
|
||||||
|
return &fxevent.ZapLogger{Logger: logger}
|
||||||
|
}),
|
||||||
).Run()
|
).Run()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
package logger
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.uber.org/zap"
|
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
"go.uber.org/zap"
|
||||||
|
|
||||||
"git.kanopo.dev/rhythm/rhythm-backend/internal/config"
|
"git.kanopo.dev/rhythm/rhythm-backend/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func New(env string) *zap.SugaredLogger {
|
func New(env string) (*zap.Logger, *zap.SugaredLogger) {
|
||||||
var zapLogger *zap.Logger
|
var zapLogger *zap.Logger
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@ -21,10 +22,10 @@ func New(env string) *zap.SugaredLogger {
|
|||||||
log.Fatalf("failed to initialize zap logger: %v", err)
|
log.Fatalf("failed to initialize zap logger: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return zapLogger.Sugar()
|
return zapLogger, zapLogger.Sugar()
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFromConfig(cfg *config.Config) *zap.SugaredLogger {
|
func ProvideLogger(cfg *config.Config) (*zap.Logger, *zap.SugaredLogger) {
|
||||||
return New(cfg.AppEnv)
|
return New(cfg.AppEnv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user