69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
package http
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
"time"
|
|
|
|
"git.arav.top/Arav/dwelling-home/pkg/mindflow"
|
|
"git.arav.top/Arav/dwelling-home/web"
|
|
)
|
|
|
|
type Handlers struct {
|
|
captchaExpire time.Duration
|
|
databasesPath string
|
|
guestbookOwner string
|
|
guestbookPageSize int
|
|
}
|
|
|
|
func NewHandlers(captchaExpire time.Duration, dbPath, gbOwner string, gbPageSize int) *Handlers {
|
|
return &Handlers{
|
|
captchaExpire: captchaExpire,
|
|
databasesPath: dbPath,
|
|
guestbookOwner: gbOwner,
|
|
guestbookPageSize: gbPageSize}
|
|
}
|
|
|
|
func (h *Handlers) AssetsFS() http.FileSystem {
|
|
return web.Assets()
|
|
}
|
|
|
|
func (h *Handlers) Index(w http.ResponseWriter, r *http.Request) {
|
|
web.Index("", w)
|
|
}
|
|
|
|
func (h *Handlers) Stuff(w http.ResponseWriter, r *http.Request) {
|
|
web.Stuff("/ Stuff", "", "", w)
|
|
}
|
|
|
|
func (h *Handlers) Mindflow(w http.ResponseWriter, r *http.Request) {
|
|
posts := []mindflow.Post{
|
|
{Category: "Kek", Date: time.Now(), Title: "LMAO", Body: "Testing!"},
|
|
}
|
|
web.Mindflow("/ Mindflow", posts, r, w)
|
|
}
|
|
|
|
func (h *Handlers) About(w http.ResponseWriter, r *http.Request) {
|
|
web.About("/ About", "", nil, w)
|
|
}
|
|
|
|
func (h *Handlers) Article(w http.ResponseWriter, r *http.Request) {
|
|
name := r.URL.Path[strings.LastIndex(r.URL.Path, "/")+1:]
|
|
artcl, err := web.GetArticle(name)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusNotFound)
|
|
return
|
|
}
|
|
|
|
web.Article(artcl.Title, artcl.Description, string(artcl.Body), artcl.Date, r.Host, name, r, w)
|
|
}
|
|
|
|
func (h *Handlers) RSS(w http.ResponseWriter, r *http.Request) {
|
|
web.RSS(r.Host, "Arav", nil, r, w)
|
|
}
|
|
|
|
func (h *Handlers) Robots(w http.ResponseWriter, r *http.Request) {
|
|
data, _ := web.AssetsGetFile("robots.txt")
|
|
w.Write(data)
|
|
}
|