1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-15 14:30:26 +00:00
mycorrhiza/viewutil/meta.go

31 lines
591 B
Go
Raw Normal View History

2022-03-29 20:59:36 +00:00
package viewutil
import (
"github.com/bouncepaw/mycorrhiza/l18n"
"github.com/bouncepaw/mycorrhiza/user"
"io"
"net/http"
)
// Meta is a bundle of common stuffs used by views, templates.
type Meta struct {
Lc *l18n.Localizer
U *user.User
W io.Writer
Addr string
2022-03-29 20:59:36 +00:00
}
// MetaFrom makes a Meta from the given data. You are meant to further modify it.
func MetaFrom(w http.ResponseWriter, rq *http.Request) Meta {
return Meta{
Lc: l18n.FromRequest(rq),
U: user.FromRequest(rq),
W: w,
Addr: rq.URL.Path,
2022-03-29 20:59:36 +00:00
}
}
func (m Meta) Locale() string {
2022-03-29 20:59:36 +00:00
return m.Lc.Locale
}