improve project structure

This commit is contained in:
Muhammed Efe Cetin
2025-03-16 13:32:49 +03:00
committed by M. Efe Çetin
parent b283b1568f
commit b5ee197ac7
23 changed files with 216 additions and 84 deletions

View File

@@ -7,8 +7,8 @@ import (
"net/http"
"strings"
"github.com/armbian/ansi-hastebin/keygenerator"
"github.com/armbian/ansi-hastebin/storage"
"github.com/armbian/ansi-hastebin/internal/keygenerator"
"github.com/armbian/ansi-hastebin/internal/storage"
"github.com/go-chi/chi/v5"
"github.com/sirupsen/logrus"
)
@@ -22,7 +22,6 @@ type DocumentHandler struct {
}
func NewDocumentHandler(keyLength, maxLength int, store storage.Storage, keyGenerator keygenerator.KeyGenerator) *DocumentHandler {
keyLength = 10
return &DocumentHandler{
KeyLength: keyLength,
MaxLength: maxLength,
@@ -31,6 +30,20 @@ func NewDocumentHandler(keyLength, maxLength int, store storage.Storage, keyGene
}
}
// RegisterRoutes registers document routes
func (h *DocumentHandler) RegisterRoutes(r chi.Router) {
r.Get("/raw/{id}", h.HandleRawGet)
r.Head("/raw/{id}", h.HandleRawGet)
r.Post("/log", h.HandlePutLog)
r.Put("/log", h.HandlePutLog)
r.Post("/documents", h.HandlePost)
r.Get("/documents/{id}", h.HandleGet)
r.Head("/documents/{id}", h.HandleGet)
}
// Handle retrieving a document
func (h *DocumentHandler) HandleGet(w http.ResponseWriter, r *http.Request) {
key := strings.Split(chi.URLParam(r, "id"), ".")[0]