Skip to content

Commit

Permalink
opt
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettladley committed Feb 5, 2024
1 parent 3171ff1 commit f560112
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
6 changes: 5 additions & 1 deletion backend/src/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ import (
func Init(db *gorm.DB, settings config.Settings) *fiber.App {
app := newFiberApp()

validate := utilities.RegisterCustomValidators()
validate, err := utilities.RegisterCustomValidators()
if err != nil {
panic(err)
}

middlewareService := middleware.NewMiddlewareService(db, validate, settings.Auth)

apiv1 := app.Group("/api/v1")
Expand Down
35 changes: 17 additions & 18 deletions backend/src/utilities/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,32 @@ import (
"github.com/go-playground/validator/v10"
)

func RegisterCustomValidators() *validator.Validate {
func RegisterCustomValidators() (*validator.Validate, error) {
validate := validator.New(validator.WithRequiredStructEnabled())

err := validate.RegisterValidation("neu_email", validateEmail)
if err != nil {
panic(err)
if err := validate.RegisterValidation("neu_email", validateEmail); err != nil {
return nil, err
}
err = validate.RegisterValidation("password", validatePassword)
if err != nil {
panic(err)

if err := validate.RegisterValidation("password", validatePassword); err != nil {
return nil, err
}
err = validate.RegisterValidation("mongo_url", validateMongoURL)
if err != nil {
panic(err)

if err := validate.RegisterValidation("mongo_url", validateMongoURL); err != nil {
return nil, err
}
err = validate.RegisterValidation("s3_url", validateS3URL)
if err != nil {
panic(err)

if err := validate.RegisterValidation("s3_url", validateS3URL); err != nil {
return nil, err
}
err = validate.RegisterValidation("contact_pointer", func(fl validator.FieldLevel) bool {

if err := validate.RegisterValidation("contact_pointer", func(fl validator.FieldLevel) bool {
return validateContactPointer(validate, fl)
})
if err != nil {
panic(err)
}); err != nil {
return nil, err
}

return validate
return validate, nil
}

func validateEmail(fl validator.FieldLevel) bool {
Expand Down
7 changes: 5 additions & 2 deletions cli/commands/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,30 @@ func LintCommand() *cli.Command {
func Lint(folder string, runFrontend bool, runBackend bool) error {
var wg sync.WaitGroup
errChan := make(chan error, 1)
var errOccurred bool // Flag to indicate whether an error has occurred

// Start the backend if specified
if runBackend {
if runBackend && !errOccurred {
wg.Add(1)
go func() {
defer wg.Done()
err := BackendLint()
if err != nil {
errChan <- err
errOccurred = true
}
}()
}

// Start the frontend if specified
if runFrontend {
if runFrontend && !errOccurred {
wg.Add(1)
go func() {
defer wg.Done()
err := FrontendLint(folder)
if err != nil {
errChan <- err
errOccurred = true
}
}()
}
Expand Down
8 changes: 5 additions & 3 deletions cli/commands/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,29 @@ func TestCommand() *cli.Command {
func Test(folder string, runFrontend bool, runBackend bool) error {
var wg sync.WaitGroup
errChan := make(chan error, 1)
var errOccurred bool // Flag to indicate whether an error has occurred

// Start the backend if specified
if runBackend {
if runBackend && !errOccurred {
wg.Add(1)
go func() {
defer wg.Done()
err := BackendTest()
if err != nil {
errChan <- err
errOccurred = true
}
}()
}

// Start the frontend if specified
if runFrontend {
if runFrontend && !errOccurred {
wg.Add(1)
go func() {
defer wg.Done()
err := FrontendTest(folder)
if err != nil {
errChan <- err
errOccurred = true
}
}()
}
Expand Down

0 comments on commit f560112

Please sign in to comment.