mirror of
https://github.com/dnote/dnote
synced 2026-03-14 22:45:50 +01:00
* Embed files * Build CLI * Remove packr * Embed view directory * Embed static files * Make view engine * Populate build info
35 lines
874 B
Go
35 lines
874 B
Go
package controllers
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/dnote/dnote/pkg/server/app"
|
|
"github.com/dnote/dnote/pkg/server/views"
|
|
)
|
|
|
|
// NewStatic creates a new Static controller.
|
|
func NewStatic(app *app.App, viewEngine *views.Engine) *Static {
|
|
return &Static{
|
|
NotFoundView: viewEngine.NewView(app, views.Config{Title: "Not Found", Layout: "base"}, "static/not_found"),
|
|
}
|
|
}
|
|
|
|
// Static is a static controller
|
|
type Static struct {
|
|
NotFoundView *views.View
|
|
}
|
|
|
|
// NotFound is a catch-all handler for requests with no matching handler
|
|
func (s *Static) NotFound(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusNotFound)
|
|
|
|
accept := r.Header.Get("Accept")
|
|
|
|
if strings.Contains(accept, "text/html") {
|
|
s.NotFoundView.Render(w, r, nil, http.StatusOK)
|
|
} else {
|
|
statusText := http.StatusText(http.StatusNotFound)
|
|
w.Write([]byte(statusText))
|
|
}
|
|
}
|