changes required to convert to Echo v5
This commit is contained in:
+6
-6
@@ -27,7 +27,7 @@ import (
|
||||
"git.erbosoft.com/amy/amsterdam/database"
|
||||
"git.erbosoft.com/amy/amsterdam/util"
|
||||
"github.com/CloudyKit/jet/v6"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v5"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -98,7 +98,7 @@ type AmContext interface {
|
||||
|
||||
// amContext is the internal structure that implements AmContext.
|
||||
type amContext struct {
|
||||
echoContext echo.Context
|
||||
echoContext *echo.Context
|
||||
rendervars jet.VarMap
|
||||
frameTitle string
|
||||
frameMeta map[int]map[string]string
|
||||
@@ -243,7 +243,7 @@ func (c *amContext) FormFieldIsSet(name string) bool {
|
||||
|
||||
// FormFieldValues returns all values for a specified parameter name.
|
||||
func (c *amContext) FormFieldValues(name string) ([]string, error) {
|
||||
vals, err := c.echoContext.FormParams()
|
||||
vals, err := c.echoContext.FormValues()
|
||||
if err != nil {
|
||||
return make([]string, 0), err
|
||||
}
|
||||
@@ -525,7 +525,7 @@ var amContextRecycleBin chan *amContext
|
||||
* Internal Amsterdam context structure pointer, or nil.
|
||||
* Standard Go error status.
|
||||
*/
|
||||
func newContext(ctxt echo.Context) (*amContext, error) {
|
||||
func newContext(ctxt *echo.Context) (*amContext, error) {
|
||||
var rc *amContext
|
||||
tmp := freeContext.Get()
|
||||
if tmp == nil {
|
||||
@@ -593,7 +593,7 @@ func newContext(ctxt echo.Context) (*amContext, error) {
|
||||
* Returns:
|
||||
* The associated AmContext.
|
||||
*/
|
||||
func AmContextFromEchoContext(ctxt echo.Context) AmContext {
|
||||
func AmContextFromEchoContext(ctxt *echo.Context) AmContext {
|
||||
myctxt := ctxt.Get("__amsterdam_context")
|
||||
if myctxt != nil {
|
||||
rc, ok := myctxt.(*amContext)
|
||||
@@ -641,7 +641,7 @@ func setupContext() func() {
|
||||
|
||||
// ContextCreator is middleware that creates and recycles the AmContext.
|
||||
func ContextCreator(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
return func(c *echo.Context) error {
|
||||
myctxt, err := newContext(c)
|
||||
if err == nil {
|
||||
err = next(c)
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ import (
|
||||
|
||||
"git.erbosoft.com/amy/amsterdam/config"
|
||||
"git.erbosoft.com/amy/amsterdam/database"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v5"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -410,7 +410,7 @@ func setupSessionManager() func() {
|
||||
|
||||
// SessionStoreInjector is middleware that injects the session store into the context variables.
|
||||
func SessionStoreInjector(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
return func(c *echo.Context) error {
|
||||
c.Set("AmSessionStore", sessionStore)
|
||||
return next(c)
|
||||
}
|
||||
|
||||
+3
-3
@@ -29,7 +29,7 @@ import (
|
||||
|
||||
"git.erbosoft.com/amy/amsterdam/database"
|
||||
"github.com/disintegration/imaging"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v5"
|
||||
)
|
||||
|
||||
//go:embed static_images/*
|
||||
@@ -64,7 +64,7 @@ func mimeTypeFromFilename(filename string) string {
|
||||
* Returns:
|
||||
* Standard Go error return.
|
||||
*/
|
||||
func AmServeImage(c echo.Context) error {
|
||||
func AmServeImage(c *echo.Context) error {
|
||||
components := strings.SplitAfter(c.Request().URL.Path, "/")
|
||||
var err error = nil
|
||||
if len(components) == 4 {
|
||||
@@ -105,7 +105,7 @@ func AmServeImage(c echo.Context) error {
|
||||
* Returns:
|
||||
* Standard Go error return.
|
||||
*/
|
||||
func AmServeVeniceCompatibleImage(c echo.Context) error {
|
||||
func AmServeVeniceCompatibleImage(c *echo.Context) error {
|
||||
id, err := strconv.Atoi(c.Param("id"))
|
||||
if err == nil {
|
||||
var img *database.ImageStore
|
||||
|
||||
+9
-9
@@ -21,17 +21,17 @@ import (
|
||||
|
||||
"git.erbosoft.com/amy/amsterdam/config"
|
||||
"git.erbosoft.com/amy/amsterdam/database"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v5"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// IPBanTest is middleware that handles the IP banning.
|
||||
func IPBanTest(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
return func(c *echo.Context) error {
|
||||
// Check IP banning.
|
||||
banmsg, banerr := database.AmTestIPBan(c.Request().Context(), c.RealIP())
|
||||
if banerr != nil {
|
||||
c.Logger().Warnf("address %s could not be tested: %v", c.RealIP(), banerr)
|
||||
log.Warnf("address %s could not be tested: %v", c.RealIP(), banerr)
|
||||
// but let the request pass anyway
|
||||
} else if banmsg != "" {
|
||||
amctxt := AmContextFromEchoContext(c)
|
||||
@@ -43,7 +43,7 @@ func IPBanTest(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
|
||||
// CookieLoginTest is middleware that handles cookie logins.
|
||||
func CookieLoginTest(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
return func(c *echo.Context) error {
|
||||
amctxt := AmContextFromEchoContext(c)
|
||||
// Check for cookie login.
|
||||
if amctxt.CurrentUser().IsAnon {
|
||||
@@ -77,11 +77,11 @@ func CookieLoginTest(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
|
||||
// SetCommunity is middleware that sets the community context based on the URL.
|
||||
func SetCommunity(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
return func(c *echo.Context) error {
|
||||
ctxt := AmContextFromEchoContext(c)
|
||||
err := ctxt.SetCommunityContext(ctxt.URLParam("cid"))
|
||||
if err != nil {
|
||||
return AmSendPageData(c, ctxt, "error", echo.NewHTTPError(http.StatusNotFound).SetInternal(err))
|
||||
return AmSendPageData(c, ctxt, "error", echo.NewHTTPError(http.StatusNotFound, err.Error()).Wrap(err))
|
||||
}
|
||||
var b strings.Builder
|
||||
b.WriteString("/comm/")
|
||||
@@ -94,7 +94,7 @@ func SetCommunity(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
|
||||
// ValidateConference is middleware that validates the user has access to the community's conference facility.
|
||||
func ValidateConference(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
return func(c *echo.Context) error {
|
||||
ctxt := AmContextFromEchoContext(c)
|
||||
comm := ctxt.CurrentCommunity() // set by middleware
|
||||
b, err := database.AmTestService(c.Request().Context(), comm, "Conference")
|
||||
@@ -116,7 +116,7 @@ func ValidateConference(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
|
||||
// SetConference is middleware that sets the conference context based on the URL.
|
||||
func SetConference(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
return func(c *echo.Context) error {
|
||||
ctxt := AmContextFromEchoContext(c)
|
||||
conf, err := database.AmGetConferenceByAlias(ctxt.Ctx(), ctxt.CurrentCommunity().Id, ctxt.URLParam("confid"))
|
||||
if err != nil {
|
||||
@@ -144,7 +144,7 @@ func SetConference(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
|
||||
// SetTopic is middleware that sets the topic context based on the URL.
|
||||
func SetTopic(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
return func(c *echo.Context) error {
|
||||
ctxt := AmContextFromEchoContext(c)
|
||||
conf := ctxt.GetScratch("currentConference").(*database.Conference)
|
||||
|
||||
|
||||
+9
-9
@@ -21,7 +21,7 @@ import (
|
||||
"git.erbosoft.com/amy/amsterdam/config"
|
||||
"git.erbosoft.com/amy/amsterdam/database"
|
||||
"github.com/klauspost/lctime"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v5"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -44,7 +44,7 @@ import (
|
||||
* Returns:
|
||||
* Standard Go error status.
|
||||
*/
|
||||
func AmSendPageData(ctxt echo.Context, amctxt AmContext, command string, data any) error {
|
||||
func AmSendPageData(ctxt *echo.Context, amctxt AmContext, command string, data any) error {
|
||||
// Preprocess certain commands into different ones.
|
||||
httprc := http.StatusOK
|
||||
switch command {
|
||||
@@ -56,7 +56,7 @@ func AmSendPageData(ctxt echo.Context, amctxt AmContext, command string, data an
|
||||
httprc = he.Code
|
||||
m1 := he.Message
|
||||
e1 := he.Unwrap()
|
||||
if m1 == nil || m1 == "" {
|
||||
if m1 == "" {
|
||||
if e1 == nil {
|
||||
message = fmt.Sprintf("Unspecified error in %s", ctxt.Request().URL.String())
|
||||
} else {
|
||||
@@ -114,7 +114,7 @@ func AmSendPageData(ctxt echo.Context, amctxt AmContext, command string, data an
|
||||
err = ctxt.Render(httprc, data.(string), amctxt)
|
||||
case "framed":
|
||||
if amctxt.FrameTitle() == "" {
|
||||
ctxt.Logger().Errorf("*** NO FRAME TITLE set for path %s", amctxt.URLPath())
|
||||
log.Errorf("*** NO FRAME TITLE set for path %s", amctxt.URLPath())
|
||||
amctxt.SetFrameTitle("<<< NO FRAME TITLE >>>")
|
||||
}
|
||||
amctxt.VarMap().Set("__innerPage", data)
|
||||
@@ -177,7 +177,7 @@ type AmPageFunc func(AmContext) (string, any)
|
||||
* The wrapped function.
|
||||
*/
|
||||
func AmWrap(myfunc AmPageFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
return func(c *echo.Context) error {
|
||||
ctxt := AmContextFromEchoContext(c)
|
||||
|
||||
// Add the dynamic headers.
|
||||
@@ -191,11 +191,11 @@ func AmWrap(myfunc AmPageFunc) echo.HandlerFunc {
|
||||
ctxt.SetSession("lastKnownGood", ctxt.Locator())
|
||||
}
|
||||
if err := ctxt.SaveSession(); err != nil {
|
||||
c.Logger().Errorf("Session save error: %v", err)
|
||||
log.Errorf("Session save error: %v", err)
|
||||
return err
|
||||
}
|
||||
if err := AmSendPageData(c, ctxt, command, arg); err != nil {
|
||||
c.Logger().Errorf("Rendering error: %v", err)
|
||||
log.Errorf("Rendering error: %v", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -203,7 +203,7 @@ func AmWrap(myfunc AmPageFunc) echo.HandlerFunc {
|
||||
}
|
||||
|
||||
// AmWithTempContext runs a page function with a temporary context. Used in error handling.
|
||||
func AmWithTempContext(c echo.Context, fn AmPageFunc) error {
|
||||
func AmWithTempContext(c *echo.Context, fn AmPageFunc) error {
|
||||
var ctxt AmContext = nil
|
||||
myctxt := c.Get("__amsterdam_context")
|
||||
if myctxt != nil {
|
||||
@@ -233,7 +233,7 @@ func AmWithTempContext(c echo.Context, fn AmPageFunc) error {
|
||||
c.Response().Header().Set("Expires", expireTime)
|
||||
|
||||
if err := AmSendPageData(c, ctxt, command, arg); err != nil {
|
||||
c.Logger().Errorf("Rendering error: %v", err)
|
||||
log.Errorf("Rendering error: %v", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"git.erbosoft.com/amy/amsterdam/config"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v5"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"golang.org/x/net/html"
|
||||
)
|
||||
|
||||
+2
-2
@@ -31,7 +31,7 @@ import (
|
||||
"github.com/CloudyKit/jet/v6"
|
||||
"github.com/CloudyKit/jet/v6/loaders/embedfs"
|
||||
"github.com/CloudyKit/jet/v6/loaders/multi"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v5"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -363,7 +363,7 @@ type TemplateRenderer struct{}
|
||||
* Returns:
|
||||
* Standard Go error status.
|
||||
*/
|
||||
func (r *TemplateRenderer) Render(w io.Writer, name string, data any, c echo.Context) error {
|
||||
func (r *TemplateRenderer) Render(c *echo.Context, w io.Writer, name string, data any) error {
|
||||
defer util.MeasureTime(fmt.Sprintf("ui.Render(%s)", name))()
|
||||
|
||||
view, err := views.GetTemplate(name)
|
||||
|
||||
Reference in New Issue
Block a user