refac: hardening pass with multiple overhauls
This commit is contained in:
1 parent
b0f7b7892b
commit
da36c78bc0
28 files changed
+1375
-39
No files matched your search
@@ -12,6 +12,7 @@ import (
|
||||
"RenewCMS/internal/infrastructure/persistence/models"
|
||||
persistence "RenewCMS/internal/infrastructure/persistence/repositories"
|
||||
"RenewCMS/internal/infrastructure/useCases"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -53,11 +54,17 @@ type Repositories struct {
|
||||
MailRepo domainMail.Repository
|
||||
}
|
||||
|
||||
const sqliteBusyTimeoutMs = 5000
|
||||
|
||||
func SQLiteDSN(dbName string) string {
|
||||
return fmt.Sprintf("%s?_pragma=busy_timeout(%d)", dbName, sqliteBusyTimeoutMs)
|
||||
}
|
||||
|
||||
func getDb(dbName string) *gorm.DB {
|
||||
if err := os.MkdirAll(filepath.Dir(dbName), os.ModePerm); err != nil {
|
||||
panic("Unable to create necessary subdirectories: " + err.Error())
|
||||
}
|
||||
db, err := gorm.Open(sqlite.Open(dbName), &gorm.Config{})
|
||||
db, err := gorm.Open(sqlite.Open(SQLiteDSN(dbName)), &gorm.Config{})
|
||||
if err != nil {
|
||||
panic("Unable to open the database: " + err.Error())
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ type InviteHandler struct {
|
||||
}
|
||||
|
||||
type CreateInviteRequest struct {
|
||||
Email string `json:"email" validate:"required,email"`
|
||||
Email string `json:"email" validate:"required,inviteemail"`
|
||||
}
|
||||
|
||||
type inviteResponse struct {
|
||||
|
||||
@@ -1,9 +1,22 @@
|
||||
package validator
|
||||
|
||||
import "github.com/go-playground/validator/v10"
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
const inviteEmailTag = "inviteemail"
|
||||
|
||||
var inviteEmailPattern = regexp.MustCompile(`^[^\s@]+@[^\s@.]+(\.[^\s@.]+)+$`)
|
||||
|
||||
var Validate *validator.Validate
|
||||
|
||||
func InitValidator() {
|
||||
Validate = validator.New()
|
||||
_ = Validate.RegisterValidation(inviteEmailTag, isInviteEmail)
|
||||
}
|
||||
|
||||
func isInviteEmail(field validator.FieldLevel) bool {
|
||||
return inviteEmailPattern.MatchString(field.Field().String())
|
||||
}
|
||||
Reference in new issue
Block a user