Initial commit.
This commit is contained in:
commit
63f43e568c
23 changed files with 1199 additions and 0 deletions
54
controllers/page.go
Normal file
54
controllers/page.go
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
"goweb/msg"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type Page struct {
|
||||
AppName string
|
||||
Title string
|
||||
Context echo.Context
|
||||
Reverse func(name string, params ...interface{}) string
|
||||
Path string
|
||||
Data interface{}
|
||||
Layout string
|
||||
Name string
|
||||
IsHome bool
|
||||
IsAuth bool
|
||||
StatusCode int
|
||||
Metatags struct {
|
||||
Description string
|
||||
Keywords []string
|
||||
}
|
||||
}
|
||||
|
||||
func NewPage(c echo.Context) Page {
|
||||
p := Page{
|
||||
Context: c,
|
||||
Reverse: c.Echo().Reverse,
|
||||
Path: c.Request().URL.Path,
|
||||
StatusCode: http.StatusOK,
|
||||
}
|
||||
|
||||
p.IsHome = p.Path == "/"
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p Page) SetMessage(typ msg.Type, value string) {
|
||||
msg.Set(p.Context, typ, value)
|
||||
}
|
||||
|
||||
func (p Page) GetMessages(typ msg.Type) []template.HTML {
|
||||
strs := msg.Get(p.Context, typ)
|
||||
ret := make([]template.HTML, len(strs))
|
||||
for k, v := range strs {
|
||||
ret[k] = template.HTML(v)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue