1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-14 06:10:26 +00:00
mycorrhiza/viewutil/meta.go
Timur Ismagilov d7b4ea9002 Embed data-rrh-addr attribute on all pages
You can define the attribute more precisely if you want to
2022-04-23 21:53:15 +03:00

31 lines
591 B
Go

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
}
// 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,
}
}
func (m Meta) Locale() string {
return m.Lc.Locale
}