(sectionName string, required bool, callbacks ...ValidatorCallback)
| 222 | } |
| 223 | |
| 224 | func (a *Application) stringSection(sectionName string, required bool, callbacks ...ValidatorCallback) string { |
| 225 | value, exists := a.sections[sectionName] |
| 226 | _, value, _ = ParseInput(value) |
| 227 | |
| 228 | // If the section is required, apply the presence validator if the entry |
| 229 | // exists, early fail validation if it doesn't exist. If the section is |
| 230 | // not required and there is no content to work with, don't try to run |
| 231 | // additional validations. |
| 232 | if required { |
| 233 | if exists { |
| 234 | callbacks = append([]ValidatorCallback{IsPresent}, callbacks...) |
| 235 | } else { |
| 236 | a.validator.AddError(sectionName, value, "was not completed for application") |
| 237 | return value |
| 238 | } |
| 239 | } else if !exists || value == "" { |
| 240 | return value |
| 241 | } |
| 242 | |
| 243 | for _, callback := range callbacks { |
| 244 | pass, newValue, message := callback(value) |
| 245 | value = newValue |
| 246 | |
| 247 | if !pass { |
| 248 | a.validator.AddError(sectionName, value, message) |
| 249 | break |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | return value |
| 254 | } |
| 255 | |
| 256 | func (a *Application) intSection(sectionName string, required bool, callbacks ...ValidatorCallback) int { |
| 257 | value := a.stringSection(sectionName, required, callbacks...) |
no test coverage detected