Aded test coverage for form submissions. Added validator as a service.

This commit is contained in:
mikestefanello 2021-12-25 00:11:59 -05:00
parent cc2f25431b
commit 6501621136
8 changed files with 111 additions and 30 deletions

View file

@ -8,8 +8,6 @@ import (
"goweb/middleware"
"goweb/services"
"github.com/go-playground/validator/v10"
"github.com/gorilla/sessions"
"github.com/labstack/echo-contrib/session"
@ -17,19 +15,6 @@ import (
echomw "github.com/labstack/echo/v4/middleware"
)
type Validator struct {
validator *validator.Validate
}
func (v *Validator) Validate(i interface{}) error {
if err := v.validator.Struct(i); err != nil {
return err
}
return nil
}
// TODO: This is doing more than building the router
func BuildRouter(c *services.Container) {
// Static files with proper cache control
// funcmap.File() should be used in templates to append a cache key to the URL in order to break cache
@ -73,9 +58,6 @@ func BuildRouter(c *services.Container) {
err := Error{Controller: ctr}
c.Web.HTTPErrorHandler = err.Get
// Validator
c.Web.Validator = &Validator{validator: validator.New()}
// Routes
navRoutes(c, g, ctr)
userRoutes(c, g, ctr)