feat: pass file storage instance
This commit is contained in:
@ -9,6 +9,7 @@ import (
|
||||
"gitea.local/admin/hspguard/internal/auth"
|
||||
imiddleware "gitea.local/admin/hspguard/internal/middleware"
|
||||
"gitea.local/admin/hspguard/internal/repository"
|
||||
"gitea.local/admin/hspguard/internal/storage"
|
||||
"gitea.local/admin/hspguard/internal/user"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
@ -17,12 +18,14 @@ import (
|
||||
type APIServer struct {
|
||||
addr string
|
||||
repo *repository.Queries
|
||||
storage *storage.FileStorage
|
||||
}
|
||||
|
||||
func NewAPIServer(addr string, db *repository.Queries) *APIServer {
|
||||
func NewAPIServer(addr string, db *repository.Queries, minio *storage.FileStorage) *APIServer {
|
||||
return &APIServer{
|
||||
addr: addr,
|
||||
repo: db,
|
||||
storage: minio,
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,7 +40,7 @@ func (s *APIServer) Run() error {
|
||||
router.Route("/api/v1", func(r chi.Router) {
|
||||
r.Use(imiddleware.WithSkipper(imiddleware.AuthMiddleware, "/api/v1/login", "/api/v1/register"))
|
||||
|
||||
userHandler := user.NewUserHandler(s.repo)
|
||||
userHandler := user.NewUserHandler(s.repo, s.storage)
|
||||
userHandler.RegisterRoutes(r)
|
||||
|
||||
authHandler := auth.NewAuthHandler(s.repo)
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
|
||||
"gitea.local/admin/hspguard/cmd/hspguard/api"
|
||||
"gitea.local/admin/hspguard/internal/repository"
|
||||
"gitea.local/admin/hspguard/internal/storage"
|
||||
"gitea.local/admin/hspguard/internal/user"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/joho/godotenv"
|
||||
@ -30,6 +31,8 @@ func main() {
|
||||
|
||||
repo := repository.New(conn)
|
||||
|
||||
fStorage := storage.New()
|
||||
|
||||
user.EnsureAdminUser(ctx, repo)
|
||||
|
||||
host := os.Getenv("HOST")
|
||||
@ -42,7 +45,7 @@ func main() {
|
||||
port = "3000"
|
||||
}
|
||||
|
||||
server := api.NewAPIServer(fmt.Sprintf("127.0.0.1:%s", port), repo)
|
||||
server := api.NewAPIServer(fmt.Sprintf("127.0.0.1:%s", port), repo, fStorage)
|
||||
if err := server.Run(); err != nil {
|
||||
log.Fatalln("ERR: Failed to start server:", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user