subscribe-bot/web/render.go
2021-07-22 03:32:53 -05:00

30 lines
516 B
Go

package web
import (
"log"
"net/http"
"github.com/gin-gonic/gin"
)
func (web *Web) errorWrap(fn func(*gin.Context) error) func(*gin.Context) {
return func(c *gin.Context) {
err := fn(c)
if err != nil {
c.String(http.StatusInternalServerError, "error")
log.Println("fatal error", err)
}
}
}
func (web *Web) render(c *gin.Context, code int, tmpl string, obj gin.H) {
base := gin.H{
"IsLoggedIn": isLoggedIn(c),
}
for key, val := range obj {
base[key] = val
}
c.HTML(code, tmpl, base)
}