2025-01-11 19:10:18 +01:00
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"crowsnest/internal/model/database"
|
|
|
|
|
"database/sql"
|
|
|
|
|
"net/http"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type App struct {
|
|
|
|
|
articles *database.ArticleModel
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewApp(db *sql.DB) *App {
|
|
|
|
|
return &App{
|
|
|
|
|
articles: &database.ArticleModel{DB: db},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (app *App) Routes() http.Handler {
|
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
|
|
|
|
|
|
// dynamic routes
|
|
|
|
|
mux.Handle("GET /", http.HandlerFunc(app.Index))
|
|
|
|
|
mux.Handle("GET /page/{id}", http.HandlerFunc(app.Index))
|
|
|
|
|
mux.Handle("POST /up/search", http.HandlerFunc(app.UpSearch))
|
|
|
|
|
|
|
|
|
|
// serve files from the "static" directory
|
2025-01-11 20:27:32 +01:00
|
|
|
mux.Handle("GET /static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./assets/static"))))
|
2025-01-11 19:10:18 +01:00
|
|
|
|
|
|
|
|
return mux
|
|
|
|
|
}
|