20 lines
497 B
Go
20 lines
497 B
Go
package validasi
|
|
|
|
import "fmt"
|
|
|
|
// IsUsiaProduktif returns true if age is between 18 and 60 inclusive.
|
|
func IsUsiaProduktif(age int) bool {
|
|
return age >= 18 && age <= 60
|
|
}
|
|
|
|
// ValidateUsia returns nil when usia produktif, otherwise an error explaining why.
|
|
func ValidateUsia(age int) error {
|
|
if age < 0 {
|
|
return fmt.Errorf("umur tidak boleh negatif")
|
|
}
|
|
if IsUsiaProduktif(age) {
|
|
return nil
|
|
}
|
|
return fmt.Errorf("umur %d bukan usia produktif (18-60)", age)
|
|
}
|