add images

This commit is contained in:
2026-03-14 16:02:33 +07:00
parent 4ae2715ab0
commit ae82f8e0d9
6 changed files with 58 additions and 11 deletions
+25
View File
@@ -19,6 +19,7 @@ import (
"log"
"net"
"net/http"
"time"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
@@ -139,6 +140,19 @@ func main() {
log.Fatalln(http.ListenAndServe(config.ClientPort, muxUser))
}()
go func() {
dir := "./data/story/images"
// Создаем файловый сервер
fs := http.FileServer(http.Dir(dir))
// Добавляем middleware для логирования
http.Handle("/", loggingMiddleware(fs))
log.Println("Файловый сервер запущен на http://localhost:8120")
log.Println("Обслуживается директория: " + dir)
log.Fatal(http.ListenAndServe(":8120", nil))
}()
muxAdmin := http.NewServeMux()
subAdminFS, err := fs.Sub(adminFS, "static/admin")
if err != nil {
@@ -163,3 +177,14 @@ func cors(h http.Handler) http.Handler {
h.ServeHTTP(w, r)
})
}
func loggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
// Логируем запрос
log.Printf("[%s] %s %s", r.Method, r.URL.Path, time.Since(start))
next.ServeHTTP(w, r)
})
}