feat: Update Fiber version to v2 and update internal controller and search logic to use new index module
This commit is contained in:
@@ -1,9 +1,23 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"git.dev-null.rocks/alexohneander/gosearch/pkg/index"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func Index(c fiber.Ctx) error {
|
||||
return c.SendString("Hello, World!")
|
||||
type Document struct {
|
||||
Url string `json:"url" xml:"url" form:"url"`
|
||||
Content string `json:"content" xml:"content" form:"content"`
|
||||
}
|
||||
|
||||
func AddDocumentToIndex(c *fiber.Ctx) error {
|
||||
doc := new(Document)
|
||||
|
||||
if err := c.BodyParser(doc); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
index.AddDocToIndex(doc.Url, doc.Content)
|
||||
|
||||
return c.SendString("Document added")
|
||||
}
|
||||
|
@@ -5,16 +5,17 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"git.dev-null.rocks/alexohneander/gosearch/pkg/index"
|
||||
"git.dev-null.rocks/alexohneander/gosearch/pkg/search"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func SearchQuery(c fiber.Ctx) error {
|
||||
func SearchQuery(c *fiber.Ctx) error {
|
||||
query := c.Params("query")
|
||||
query = strings.TrimSpace(query)
|
||||
|
||||
terms, queryType := parseQuery(query)
|
||||
results := search.Search(terms, queryType, search.Index, search.DocFreq, len(search.Files))
|
||||
results := search.Search(terms, queryType, index.Index, index.DocFreq, len(index.Documents))
|
||||
|
||||
var response string
|
||||
|
||||
|
@@ -2,24 +2,23 @@ package http
|
||||
|
||||
import (
|
||||
"git.dev-null.rocks/alexohneander/gosearch/internal/controller"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/gofiber/fiber/v3/middleware/healthcheck"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/monitor"
|
||||
)
|
||||
|
||||
func configureRoutes(app *fiber.App) *fiber.App {
|
||||
// Index
|
||||
app.Get("/", controller.Index)
|
||||
app.Get("/test", controller.Index)
|
||||
app.Post("/api/index", controller.AddDocumentToIndex)
|
||||
|
||||
// Search
|
||||
app.Get("/api/search/:query", controller.SearchQuery)
|
||||
|
||||
// Monitor
|
||||
// app.Get("/metrics", monitor.New(monitor.Config{Title: "MyService Metrics Page"}))
|
||||
app.Get("/metrics", monitor.New(monitor.Config{Title: "gosearch Metrics"}))
|
||||
|
||||
// Health Checks
|
||||
app.Get(healthcheck.DefaultLivenessEndpoint, healthcheck.NewHealthChecker())
|
||||
app.Get(healthcheck.DefaultReadinessEndpoint, healthcheck.NewHealthChecker())
|
||||
app.Get(healthcheck.DefaultStartupEndpoint, healthcheck.NewHealthChecker())
|
||||
// app.Get(healthcheck.DefaultLivenessEndpoint, healthcheck.NewHealthChecker())
|
||||
// app.Get(healthcheck.DefaultReadinessEndpoint, healthcheck.NewHealthChecker())
|
||||
// app.Get(healthcheck.DefaultStartupEndpoint, healthcheck.NewHealthChecker())
|
||||
return app
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/gofiber/fiber/v3/middleware/logger"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/logger"
|
||||
)
|
||||
|
||||
func StartService() {
|
||||
|
Reference in New Issue
Block a user