move middleware and routes/ app into internal dir
This commit is contained in:
32
src/internal/app/app.go
Normal file
32
src/internal/app/app.go
Normal file
@@ -0,0 +1,32 @@
|
||||
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
|
||||
fs := http.FileServer(http.Dir("assets/static"))
|
||||
mux.Handle("GET /static/", http.StripPrefix("/", fs))
|
||||
|
||||
return mux
|
||||
}
|
||||
Reference in New Issue
Block a user