37 lines
713 B
Go
37 lines
713 B
Go
package home
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"librapi/templates"
|
|
"net/http"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
const URL = "/"
|
|
|
|
func Handler() func(http.ResponseWriter, *http.Request) {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
switch r.Method {
|
|
case http.MethodGet:
|
|
getHome(w, r)
|
|
default:
|
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
|
}
|
|
}
|
|
}
|
|
|
|
func getHome(w http.ResponseWriter, _ *http.Request) {
|
|
home := templates.GetHome()
|
|
|
|
buf := bytes.NewBufferString("")
|
|
if err := home.Execute(buf, nil); err != nil {
|
|
log.Err(err).Msg("unable to generate template")
|
|
http.Error(w, "unexpected error occurred", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
fmt.Fprint(w, buf)
|
|
}
|