7558655458
I have put too much code into the same files. Also, I put everything into the same package: main. This package is only meant for executables. Therefore, I have refactored my code to use multiple packages. These packages also guarantee separation of concerns since Golang doesn't allow cyclic imports.
29 lines
579 B
Go
29 lines
579 B
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.ekzyis.com/ekzyis/delphi.market/db"
|
|
"git.ekzyis.com/ekzyis/delphi.market/lib"
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
func HandleIndex(envVars map[string]any) echo.HandlerFunc {
|
|
return func(c echo.Context) error {
|
|
var (
|
|
markets []db.Market
|
|
err error
|
|
data map[string]any
|
|
)
|
|
if err = db.FetchActiveMarkets(&markets); err != nil {
|
|
return err
|
|
}
|
|
data = map[string]any{
|
|
"session": c.Get("session"),
|
|
"markets": markets,
|
|
}
|
|
lib.Merge(&data, &envVars)
|
|
return c.Render(http.StatusOK, "index.html", data)
|
|
}
|
|
}
|