Add BE validator
This commit is contained in:
		
							
								
								
									
										25
									
								
								internal/validator/validator.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								internal/validator/validator.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,25 @@
 | 
			
		||||
package validator
 | 
			
		||||
 | 
			
		||||
type Validator struct {
 | 
			
		||||
	Errors map[string]string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func New() *Validator {
 | 
			
		||||
	return &Validator{Errors: make(map[string]string)}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (v *Validator) Valid() bool {
 | 
			
		||||
	return len(v.Errors) == 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (v *Validator) AddError(key, message string) {
 | 
			
		||||
	if _, exists := v.Errors[key]; !exists {
 | 
			
		||||
		v.Errors[key] = message
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (v *Validator) Check(ok bool, key, message string) {
 | 
			
		||||
	if !ok {
 | 
			
		||||
		v.AddError(key, message)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user