Adds a new feature to generate aadhar card and pan card for enin#20
Adds a new feature to generate aadhar card and pan card for enin#20
Conversation
WalkthroughThe pull request updates mock data generation by enhancing the Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant M as GenerateMockExample
participant T as SetLanguage
participant A as GenerateAadhaarNumber
participant P as GenerateRandomPAN
U->>M: Provide language input
M->>T: Set language with user input
alt Language is "enin"
M->>A: Generate Aadhaar
M->>P: Generate PAN
A-->>M: Return Aadhaar
P-->>M: Return PAN
M->>U: Display Aadhaar & PAN
else
M->>U: Process without special generation
end
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (7)
pkg/mocai/entities/gender/mocks/enin/genders.go (1)
3-15: LGTM! Comprehensive and inclusive gender list.The list includes both traditional and culturally specific gender identities relevant to the Indian context, along with globally recognized terms.
Consider adding a comment block above the
Gendersvariable to document the cultural significance of terms like "Hijra", "Aravani", and "Kothi" for better maintainability.examples/mock_example.go (1)
46-51: Follow Go naming conventions.Variable names should use camelCase instead of snake_case in Go.
Apply this diff to fix naming:
if languageID == "enin" { - aadhar_card := helper.GenerateAadhaarNumber() - pan_card := helper.GenerateRandomPAN() - fmt.Printf("Adhar card: %s\n", aadhar_card) - fmt.Printf("Pan card: %s", pan_card) + aadhaarCard := helper.GenerateAadhaarNumber() + panCard := helper.GenerateRandomPAN() + fmt.Printf("Aadhaar card: %s\n", aadhaarCard) + fmt.Printf("PAN card: %s", panCard) }Also fixed the spelling of "Aadhaar" in the output string.
pkg/mocai/entities/address/mocks/enin/zip_codes.go (2)
3-4: Update terminology in comments.Replace "ZIP codes" with "PIN codes" as that's the correct terminology used in India for postal codes.
-// ZIPCodes contains a list of 200 distinct indian ZIP codes. +// PINcodes contains a list of 200 distinct Indian PIN codes.
4-25: Consider adding PIN code validation.Consider adding a validation function to ensure all PIN codes:
- Are exactly 6 digits
- Follow the Indian postal service format
- Are valid and active codes
This will help prevent invalid data in mock generations.
pkg/mocai/entities/person/mocks/enin/first_names_female.go (1)
3-4: Fix comment typo and align with variable name.The comment has a typo and doesn't match the variable name.
-// FirstNameFemale contains a list of 200 distinct indian female first names. +// FirstNamesFemale contains a list of 200 distinct Indian female first names.pkg/mocai/entities/person/mocks/enin/first_names_male.go (1)
3-4: Fix grammar in comment.The comment has incorrect grammar.
-// FirstNameMale contains a list of 200 distinct indian first names male. +// FirstNamesMale contains a list of 200 distinct Indian male first names.pkg/mocai/entities/address/mocks/enin/cities.go (1)
3-4: Fix inaccurate comment.The comment has several inaccuracies:
- States "200 distinct cities" but contains 227 cities
- States "excluding capitals" but includes capitals like New Delhi, Gandhinagar, etc.
-// Cities contains a list of 200 distinct cities names in india (excluding capitals). +// Cities contains a list of Indian city names.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (13)
examples/mock_example.go(2 hunks)pkg/mocai/entities/address/mocks/enin/cities.go(1 hunks)pkg/mocai/entities/address/mocks/enin/states.go(1 hunks)pkg/mocai/entities/address/mocks/enin/streets.go(1 hunks)pkg/mocai/entities/address/mocks/enin/zip_codes.go(1 hunks)pkg/mocai/entities/gender/mocks/enin/genders.go(1 hunks)pkg/mocai/entities/person/mocks/enin/first_names_female.go(1 hunks)pkg/mocai/entities/person/mocks/enin/first_names_male.go(1 hunks)pkg/mocai/entities/person/mocks/enin/last_names.go(1 hunks)pkg/mocai/entities/phone/mocks/enin/area_codes.go(1 hunks)pkg/mocai/helper/helper.go(1 hunks)pkg/mocai/translations/en_in.go(1 hunks)pkg/mocai/translations/translations.go(1 hunks)
✅ Files skipped from review due to trivial changes (5)
- pkg/mocai/translations/translations.go
- pkg/mocai/entities/address/mocks/enin/states.go
- pkg/mocai/entities/phone/mocks/enin/area_codes.go
- pkg/mocai/entities/person/mocks/enin/last_names.go
- pkg/mocai/entities/address/mocks/enin/streets.go
🧰 Additional context used
🪛 golangci-lint (1.62.2)
pkg/mocai/helper/helper.go
11-11: SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative has been available since Go 1.0: As of Go 1.20 there is no reason to call Seed with a random value. Programs that call Seed with a known value to get a specific sequence of results should use New(NewSource(seed)) to obtain a local random generator.
(staticcheck)
24-24: SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative has been available since Go 1.0: As of Go 1.20 there is no reason to call Seed with a random value. Programs that call Seed with a known value to get a specific sequence of results should use New(NewSource(seed)) to obtain a local random generator.
(staticcheck)
🪛 GitHub Check: Build and Test
pkg/mocai/helper/helper.go
[failure] 11-11:
SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative has been available since Go 1.0: As of Go 1.20 there is no reason to call Seed with a random value. Programs that call Seed with a known value to get a specific sequence of results should use New(NewSource(seed)) to obtain a local random generator. (staticcheck)
[failure] 24-24:
SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative has been available since Go 1.0: As of Go 1.20 there is no reason to call Seed with a random value. Programs that call Seed with a known value to get a specific sequence of results should use New(NewSource(seed)) to obtain a local random generator. (staticcheck)
[failure] 11-11:
SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative has been available since Go 1.0: As of Go 1.20 there is no reason to call Seed with a random value. Programs that call Seed with a known value to get a specific sequence of results should use New(NewSource(seed)) to obtain a local random generator. (staticcheck)
[failure] 24-24:
SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative has been available since Go 1.0: As of Go 1.20 there is no reason to call Seed with a random value. Programs that call Seed with a known value to get a specific sequence of results should use New(NewSource(seed)) to obtain a local random generator. (staticcheck)
🔇 Additional comments (2)
pkg/mocai/entities/person/mocks/enin/first_names_female.go (1)
22-22: Verify similar-looking names.Please verify if these similar-looking names are distinct and correct:
- "Sharvani"
- "Sharvya"
- "Sharini"
- "Sharvisha"
- "Sharvanya"
They might be variations of the same name or potential duplicates.
pkg/mocai/entities/person/mocks/enin/first_names_male.go (1)
24-24: Verify similar-looking names.Please verify if these similar-looking names are distinct and correct:
- "Sumeet"
- "Sumer"
- "Sumeer"
They might be variations of the same name or potential duplicates.
pkg/mocai/helper/helper.go
Outdated
| // Generate a random Aadhaar number | ||
| func GenerateAadhaarNumber() string { | ||
| rand.Seed(time.Now().UnixNano()) | ||
| aadhaar := "" | ||
|
|
||
| for i := 0; i < 12; i++ { | ||
| aadhaar += strconv.Itoa(rand.Intn(10)) | ||
| } | ||
| return aadhaar | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Fix deprecated rand.Seed usage and enhance Aadhaar validation.
The function has the following issues:
- Uses deprecated
rand.Seedfunction. - Missing Verhoeff algorithm validation for Aadhaar numbers.
Apply this diff to fix the deprecated rand.Seed:
-func GenerateAadhaarNumber() string {
- rand.Seed(time.Now().UnixNano())
+func GenerateAadhaarNumber() string {
+ r := rand.New(rand.NewSource(time.Now().UnixNano()))
aadhaar := ""
for i := 0; i < 12; i++ {
- aadhaar += strconv.Itoa(rand.Intn(10))
+ aadhaar += strconv.Itoa(r.Intn(10))
}
return aadhaar
}Consider implementing the Verhoeff algorithm to generate valid Aadhaar numbers. Would you like me to help with the implementation?
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Generate a random Aadhaar number | |
| func GenerateAadhaarNumber() string { | |
| rand.Seed(time.Now().UnixNano()) | |
| aadhaar := "" | |
| for i := 0; i < 12; i++ { | |
| aadhaar += strconv.Itoa(rand.Intn(10)) | |
| } | |
| return aadhaar | |
| } | |
| // Generate a random Aadhaar number | |
| func GenerateAadhaarNumber() string { | |
| r := rand.New(rand.NewSource(time.Now().UnixNano())) | |
| aadhaar := "" | |
| for i := 0; i < 12; i++ { | |
| aadhaar += strconv.Itoa(r.Intn(10)) | |
| } | |
| return aadhaar | |
| } |
🧰 Tools
🪛 golangci-lint (1.62.2)
11-11: SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative has been available since Go 1.0: As of Go 1.20 there is no reason to call Seed with a random value. Programs that call Seed with a known value to get a specific sequence of results should use New(NewSource(seed)) to obtain a local random generator.
(staticcheck)
🪛 GitHub Check: Build and Test
[failure] 11-11:
SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative has been available since Go 1.0: As of Go 1.20 there is no reason to call Seed with a random value. Programs that call Seed with a known value to get a specific sequence of results should use New(NewSource(seed)) to obtain a local random generator. (staticcheck)
[failure] 11-11:
SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative has been available since Go 1.0: As of Go 1.20 there is no reason to call Seed with a random value. Programs that call Seed with a known value to get a specific sequence of results should use New(NewSource(seed)) to obtain a local random generator. (staticcheck)
pkg/mocai/helper/helper.go
Outdated
| // Function to generate a random PAN number | ||
| func GenerateRandomPAN() string { | ||
| var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
| var digits = "0123456789" | ||
| rand.Seed(time.Now().UnixNano()) | ||
|
|
||
| // Generate first 5 letters | ||
| pan := "" | ||
| for i := 0; i < 5; i++ { | ||
| pan += string(letters[rand.Intn(len(letters))]) | ||
| } | ||
|
|
||
| // Generate 4 digits | ||
| for i := 0; i < 4; i++ { | ||
| pan += string(digits[rand.Intn(len(digits))]) | ||
| } | ||
|
|
||
| // Generate last letter | ||
| pan += string(letters[rand.Intn(len(letters))]) | ||
|
|
||
| return pan | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Fix deprecated rand.Seed usage and enhance PAN validation.
The function has the following issues:
- Uses deprecated
rand.Seedfunction. - Missing validation for PAN card rules (e.g., first letter categories).
Apply this diff to fix the deprecated rand.Seed:
func GenerateRandomPAN() string {
var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var digits = "0123456789"
- rand.Seed(time.Now().UnixNano())
+ r := rand.New(rand.NewSource(time.Now().UnixNano()))
pan := ""
for i := 0; i < 5; i++ {
- pan += string(letters[rand.Intn(len(letters))])
+ pan += string(letters[r.Intn(len(letters))])
}
for i := 0; i < 4; i++ {
- pan += string(digits[rand.Intn(len(digits))])
+ pan += string(digits[r.Intn(len(digits))])
}
- pan += string(letters[rand.Intn(len(letters))])
+ pan += string(letters[r.Intn(len(letters))])
return pan
}Consider implementing PAN card validation rules:
- First character: Letter category (P for Individual, C for Company, etc.)
- Next three characters: Name-based sequence
- Fifth character: First letter of surname
Would you like me to help implement these validation rules?
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Function to generate a random PAN number | |
| func GenerateRandomPAN() string { | |
| var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
| var digits = "0123456789" | |
| rand.Seed(time.Now().UnixNano()) | |
| // Generate first 5 letters | |
| pan := "" | |
| for i := 0; i < 5; i++ { | |
| pan += string(letters[rand.Intn(len(letters))]) | |
| } | |
| // Generate 4 digits | |
| for i := 0; i < 4; i++ { | |
| pan += string(digits[rand.Intn(len(digits))]) | |
| } | |
| // Generate last letter | |
| pan += string(letters[rand.Intn(len(letters))]) | |
| return pan | |
| } | |
| // Function to generate a random PAN number | |
| func GenerateRandomPAN() string { | |
| var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
| var digits = "0123456789" | |
| r := rand.New(rand.NewSource(time.Now().UnixNano())) | |
| // Generate first 5 letters | |
| pan := "" | |
| for i := 0; i < 5; i++ { | |
| pan += string(letters[r.Intn(len(letters))]) | |
| } | |
| // Generate 4 digits | |
| for i := 0; i < 4; i++ { | |
| pan += string(digits[r.Intn(len(digits))]) | |
| } | |
| // Generate last letter | |
| pan += string(letters[r.Intn(len(letters))]) | |
| return pan | |
| } |
🧰 Tools
🪛 golangci-lint (1.62.2)
24-24: SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative has been available since Go 1.0: As of Go 1.20 there is no reason to call Seed with a random value. Programs that call Seed with a known value to get a specific sequence of results should use New(NewSource(seed)) to obtain a local random generator.
(staticcheck)
🪛 GitHub Check: Build and Test
[failure] 24-24:
SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative has been available since Go 1.0: As of Go 1.20 there is no reason to call Seed with a random value. Programs that call Seed with a known value to get a specific sequence of results should use New(NewSource(seed)) to obtain a local random generator. (staticcheck)
[failure] 24-24:
SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative has been available since Go 1.0: As of Go 1.20 there is no reason to call Seed with a random value. Programs that call Seed with a known value to get a specific sequence of results should use New(NewSource(seed)) to obtain a local random generator. (staticcheck)
| func init() { | ||
| // Choose a random state | ||
| state := address_mocks.States[rand.Intn(len(address_mocks.States))] | ||
|
|
||
| Register("enin", map[string]string{ | ||
| "person_first_name_male": person_mocks.FirstNamesMale[rand.Intn(len(person_mocks.FirstNamesMale))], | ||
| "person_first_name_female": person_mocks.FirstNamesFemale[rand.Intn(len(person_mocks.FirstNamesFemale))], | ||
| "person_last_name": person_mocks.LastNames[rand.Intn(len(person_mocks.LastNames))], | ||
| "gender": gender_mocks.Genders[rand.Intn(len(gender_mocks.Genders))], | ||
| "address_street": address_mocks.Streets[rand.Intn(len(address_mocks.Streets))], | ||
| "address_city": address_mocks.Cities[rand.Intn(len(address_mocks.Cities))], | ||
| "address_state": state, | ||
| "address_zip": address_mocks.ZIPCodes[rand.Intn(len(address_mocks.ZIPCodes))], | ||
| "phone_area_code": phone_mocks.AreaCodes[rand.Intn(len(phone_mocks.AreaCodes))], | ||
| }) | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Fix random number generation and approve registration structure.
The registration structure is well-organized and covers essential mock data fields. However, the random number generation needs improvement.
Apply this diff to fix the random number generation:
func init() {
+ r := rand.New(rand.NewSource(time.Now().UnixNano()))
// Choose a random state
- state := address_mocks.States[rand.Intn(len(address_mocks.States))]
+ state := address_mocks.States[r.Intn(len(address_mocks.States))]
Register("enin", map[string]string{
- "person_first_name_male": person_mocks.FirstNamesMale[rand.Intn(len(person_mocks.FirstNamesMale))],
- "person_first_name_female": person_mocks.FirstNamesFemale[rand.Intn(len(person_mocks.FirstNamesFemale))],
- "person_last_name": person_mocks.LastNames[rand.Intn(len(person_mocks.LastNames))],
- "gender": gender_mocks.Genders[rand.Intn(len(gender_mocks.Genders))],
- "address_street": address_mocks.Streets[rand.Intn(len(address_mocks.Streets))],
- "address_city": address_mocks.Cities[rand.Intn(len(address_mocks.Cities))],
+ "person_first_name_male": person_mocks.FirstNamesMale[r.Intn(len(person_mocks.FirstNamesMale))],
+ "person_first_name_female": person_mocks.FirstNamesFemale[r.Intn(len(person_mocks.FirstNamesFemale))],
+ "person_last_name": person_mocks.LastNames[r.Intn(len(person_mocks.LastNames))],
+ "gender": gender_mocks.Genders[r.Intn(len(gender_mocks.Genders))],
+ "address_street": address_mocks.Streets[r.Intn(len(address_mocks.Streets))],
+ "address_city": address_mocks.Cities[r.Intn(len(address_mocks.Cities))],
"address_state": state,
- "address_zip": address_mocks.ZIPCodes[rand.Intn(len(address_mocks.ZIPCodes))],
- "phone_area_code": phone_mocks.AreaCodes[rand.Intn(len(phone_mocks.AreaCodes))],
+ "address_zip": address_mocks.ZIPCodes[r.Intn(len(address_mocks.ZIPCodes))],
+ "phone_area_code": phone_mocks.AreaCodes[r.Intn(len(phone_mocks.AreaCodes))],
})
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| func init() { | |
| // Choose a random state | |
| state := address_mocks.States[rand.Intn(len(address_mocks.States))] | |
| Register("enin", map[string]string{ | |
| "person_first_name_male": person_mocks.FirstNamesMale[rand.Intn(len(person_mocks.FirstNamesMale))], | |
| "person_first_name_female": person_mocks.FirstNamesFemale[rand.Intn(len(person_mocks.FirstNamesFemale))], | |
| "person_last_name": person_mocks.LastNames[rand.Intn(len(person_mocks.LastNames))], | |
| "gender": gender_mocks.Genders[rand.Intn(len(gender_mocks.Genders))], | |
| "address_street": address_mocks.Streets[rand.Intn(len(address_mocks.Streets))], | |
| "address_city": address_mocks.Cities[rand.Intn(len(address_mocks.Cities))], | |
| "address_state": state, | |
| "address_zip": address_mocks.ZIPCodes[rand.Intn(len(address_mocks.ZIPCodes))], | |
| "phone_area_code": phone_mocks.AreaCodes[rand.Intn(len(phone_mocks.AreaCodes))], | |
| }) | |
| } | |
| func init() { | |
| r := rand.New(rand.NewSource(time.Now().UnixNano())) | |
| // Choose a random state | |
| state := address_mocks.States[r.Intn(len(address_mocks.States))] | |
| Register("enin", map[string]string{ | |
| "person_first_name_male": person_mocks.FirstNamesMale[r.Intn(len(person_mocks.FirstNamesMale))], | |
| "person_first_name_female": person_mocks.FirstNamesFemale[r.Intn(len(person_mocks.FirstNamesFemale))], | |
| "person_last_name": person_mocks.LastNames[r.Intn(len(person_mocks.LastNames))], | |
| "gender": gender_mocks.Genders[r.Intn(len(gender_mocks.Genders))], | |
| "address_street": address_mocks.Streets[r.Intn(len(address_mocks.Streets))], | |
| "address_city": address_mocks.Cities[r.Intn(len(address_mocks.Cities))], | |
| "address_state": state, | |
| "address_zip": address_mocks.ZIPCodes[r.Intn(len(address_mocks.ZIPCodes))], | |
| "phone_area_code": phone_mocks.AreaCodes[r.Intn(len(phone_mocks.AreaCodes))], | |
| }) | |
| } |
| // set the language | ||
| var languageID string | ||
| fmt.Print("Enter your language : ") | ||
| fmt.Scan(&languageID) | ||
| translations.SetLanguage(languageID) //test for : ptbr,enin |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Improve language input validation.
The current implementation lacks validation for supported languages and error handling for the input operation.
Apply this diff to add validation:
- var languageID string
- fmt.Print("Enter your language : ")
- fmt.Scan(&languageID)
- translations.SetLanguage(languageID) //test for : ptbr,enin
+ var languageID string
+ supportedLanguages := map[string]bool{"ptbr": true, "enin": true}
+ for {
+ fmt.Print("Enter your language (supported: ptbr, enin): ")
+ if _, err := fmt.Scan(&languageID); err != nil {
+ fmt.Println("Error reading input:", err)
+ continue
+ }
+ if supportedLanguages[languageID] {
+ break
+ }
+ fmt.Println("Unsupported language. Please try again.")
+ }
+ translations.SetLanguage(languageID)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // set the language | |
| var languageID string | |
| fmt.Print("Enter your language : ") | |
| fmt.Scan(&languageID) | |
| translations.SetLanguage(languageID) //test for : ptbr,enin | |
| // set the language | |
| var languageID string | |
| supportedLanguages := map[string]bool{"ptbr": true, "enin": true} | |
| for { | |
| fmt.Print("Enter your language (supported: ptbr, enin): ") | |
| if _, err := fmt.Scan(&languageID); err != nil { | |
| fmt.Println("Error reading input:", err) | |
| continue | |
| } | |
| if supportedLanguages[languageID] { | |
| break | |
| } | |
| fmt.Println("Unsupported language. Please try again.") | |
| } | |
| translations.SetLanguage(languageID) |
| var Cities = []string{ | ||
| "Mumbai", | ||
| "Delhi", | ||
| "Bangalore", | ||
| "Hyderabad", | ||
| "Ahmedabad", | ||
| "Chennai", | ||
| "Kolkata", | ||
| "Pune", | ||
| "Jaipur", | ||
| "Surat", | ||
| "Lucknow", | ||
| "Kanpur", | ||
| "Nagpur", | ||
| "Indore", | ||
| "Thane", | ||
| "Bhopal", | ||
| "Visakhapatnam", | ||
| "Patna", | ||
| "Vadodara", | ||
| "Ghaziabad", | ||
| "Ludhiana", | ||
| "Agra", | ||
| "Nashik", | ||
| "Ranchi", | ||
| "Faridabad", | ||
| "Meerut", | ||
| "Rajkot", | ||
| "Kalyan-Dombivli", | ||
| "Vasai-Virar", | ||
| "Varanasi", | ||
| "Srinagar", | ||
| "Aurangabad", | ||
| "Dhanbad", | ||
| "Amritsar", | ||
| "Navi Mumbai", | ||
| "Allahabad", | ||
| "Howrah", | ||
| "Gwalior", | ||
| "Jabalpur", | ||
| "Coimbatore", | ||
| "Vijayawada", | ||
| "Jodhpur", | ||
| "Madurai", | ||
| "Raipur", | ||
| "Kota", | ||
| "Guwahati", | ||
| "Chandigarh", | ||
| "Solapur", | ||
| "Hubli-Dharwad", | ||
| "Tiruchirappalli", | ||
| "Dehradun", | ||
| "Salem", | ||
| "Warangal", | ||
| "Thiruvananthapuram", | ||
| "Guntur", | ||
| "Bhiwandi", | ||
| "Saharanpur", | ||
| "Gorakhpur", | ||
| "Bikaner", | ||
| "Amravati", | ||
| "Noida", | ||
| "Jamshedpur", | ||
| "Bhilai", | ||
| "Cuttack", | ||
| "Firozabad", | ||
| "Kochi", | ||
| "Nellore", | ||
| "Bhavnagar", | ||
| "Dehri", | ||
| "Kurnool", | ||
| "Ajmer", | ||
| "Jhansi", | ||
| "Ujjain", | ||
| "Silchar", | ||
| "Jalandhar", | ||
| "Bilaspur", | ||
| "Thanjavur", | ||
| "Bellary", | ||
| "Muzaffarpur", | ||
| "Tirunelveli", | ||
| "Malegaon", | ||
| "Akola", | ||
| "Rajahmundry", | ||
| "Agartala", | ||
| "Bhagalpur", | ||
| "Latur", | ||
| "Durgapur", | ||
| "Korba", | ||
| "Dhule", | ||
| "Rourkela", | ||
| "Anantapur", | ||
| "Karimnagar", | ||
| "Etawah", | ||
| "Ambarnath", | ||
| "Bharatpur", | ||
| "Begusarai", | ||
| "New Delhi", | ||
| "Gandhinagar", | ||
| "Yamunanagar", | ||
| "Baranagar", | ||
| "Bhind", | ||
| "Shivpuri", | ||
| "Tumkur", | ||
| "Aligarh", | ||
| "Sikar", | ||
| "Udaipur", | ||
| "Bulandshahr", | ||
| "Sirsa", | ||
| "Moradabad", | ||
| "Shahjahanpur", | ||
| "Rampur", | ||
| "Kharagpur", | ||
| "Kishanganj", | ||
| "Maheshtala", | ||
| "Sambalpur", | ||
| "Bilimora", | ||
| "Tirupati", | ||
| "Bhiwani", | ||
| "Ratlam", | ||
| "Chhapra", | ||
| "Ujjain", | ||
| "Hardwar", | ||
| "Sitapur", | ||
| "Burhanpur", | ||
| "Bhatinda", | ||
| "Malda", | ||
| "Baripada", | ||
| "Satna", | ||
| "Chhindwara", | ||
| "Hosur", | ||
| "Katihar", | ||
| "Rewa", | ||
| "Nagaur", | ||
| "Chittoor", | ||
| "Bhadrak", | ||
| "Jagdalpur", | ||
| "Vidisha", | ||
| "Bidar", | ||
| "Porbandar", | ||
| "Ballia", | ||
| "Bhagalpur", | ||
| "Gaya", | ||
| "Darbhanga", | ||
| "Rohtak", | ||
| "Kollam", | ||
| "Bardhaman", | ||
| "Bankura", | ||
| "Barmer", | ||
| "Midnapore", | ||
| "Hazaribagh", | ||
| "Koraput", | ||
| "Balasore", | ||
| "Nagaon", | ||
| "Tinsukia", | ||
| "Dibrugarh", | ||
| "Jorhat", | ||
| "Bongaigaon", | ||
| "Tezpur", | ||
| "Sivasagar", | ||
| "Silchar", | ||
| "Imphal", | ||
| "Dimapur", | ||
| "Aizawl", | ||
| "Kohima", | ||
| "Itanagar", | ||
| "Agartala", | ||
| "Gangtok", | ||
| "Panaji", | ||
| "Shillong", | ||
| "Port Blair", | ||
| "Puducherry", | ||
| "Kavaratti", | ||
| "Daman", | ||
| "Silvassa", | ||
| "Dispur", | ||
| "Shillong", | ||
| "Muzaffarnagar", | ||
| "Bhuj", | ||
| "Amroha", | ||
| "Churu", | ||
| "Alwar", | ||
| "Jalgaon", | ||
| "Fatehpur", | ||
| "Sehore", | ||
| "Vidisha", | ||
| "Hajipur", | ||
| "Bhind", | ||
| "Chhatarpur", | ||
| "Khandwa", | ||
| "Daltonganj", | ||
| "Raigarh", | ||
| "Shahdol", | ||
| "Chandrapur", | ||
| "Parbhani", | ||
| "Sangli", | ||
| "Loni", | ||
| "Yavatmal", | ||
| "Satara", | ||
| "Jalna", | ||
| "Nanded", | ||
| "Hinganghat", | ||
| "Gondia", | ||
| "Bhusawal", | ||
| "Ichalkaranji", | ||
| "Betul", | ||
| "Raichur", | ||
| "Bagalkot", | ||
| "Chikmagalur", | ||
| "Davanagere", | ||
| "Mandya", | ||
| "Shivamogga", | ||
| "Tumkur", | ||
| "Kolar", | ||
| "Koppal", | ||
| "Hassan", | ||
| "Bijapur", | ||
| "Ballari", | ||
| "Gadag", | ||
| "Bidar", | ||
| "Karwar", | ||
| "Kodagu", | ||
| "Chamrajnagar", | ||
| } |
There was a problem hiding this comment.
Remove duplicate city entries.
The following cities appear multiple times in the list:
- "Shillong" (lines 173, 180)
- "Vidisha" (lines 141, 189)
- "Bhind" (lines 105, 191)
- "Silchar" (lines 78, 164)
- "Agartala" (lines 88, 170)
- "Bidar" (lines 142, 223)
- "Ujjain" (lines 77, 125)
- "Bhagalpur" (lines 89, 145)
- "Tumkur" (lines 107, 216)
Please remove the duplicates to maintain data integrity.
pkg/mocai/helper/helper.go
Outdated
| @@ -0,0 +1,44 @@ | |||
| package helper | |||
There was a problem hiding this comment.
Hey, I might be missing something, but I’m not entirely sure I understand the purpose of this helper. Is it intended to function as a generator? If so, why is it labeled as a helper and located inside helper/helper.go?
From what I can tell, based on the overall structure of the project (referencing mocai structure), wouldn’t it make more sense for this to be categorized under an entity generator instead?
The current placement may lead to confusion about its purpose and could result in future misuse by others who may not clearly understand what type of functionality belongs in this file. I'd suggest reconsidering where this fits within the architecture to ensure better alignment with the rest of the project structure and to avoid helper.go becoming a catch-all.
There was a problem hiding this comment.
thanks for the update, sure, i will put that helper file under the folder "generator"
There was a problem hiding this comment.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
examples/mock_example.go(2 hunks)pkg/mocai/entities/adhar/generator.go(1 hunks)pkg/mocai/entities/pan/generator.go(1 hunks)
🔇 Additional comments (1)
examples/mock_example.go (1)
16-20: Improve language input validation.The current implementation lacks validation for supported languages and error handling for the input operation.
| func GenerateAadhaarNumber() string { | ||
| src := rand.NewSource(time.Now().UnixNano()) | ||
| rng := rand.New(src) | ||
| aadhaar := "" | ||
|
|
||
| for i := 0; i < 12; i++ { | ||
| aadhaar += strconv.Itoa(rng.Intn(10)) | ||
| } | ||
| return aadhaar | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Enhance Aadhaar number generation with validation and security.
The current implementation has several areas for improvement:
- Add format validation for the 12-digit Aadhaar number.
- Implement checksum validation.
- Use
crypto/randinstead ofmath/randfor better security.
Apply this diff to improve the implementation:
import (
+ "crypto/rand"
- "math/rand"
+ "math/big"
"strconv"
- "time"
)
func GenerateAadhaarNumber() string {
- src := rand.NewSource(time.Now().UnixNano())
- rng := rand.New(src)
aadhaar := ""
for i := 0; i < 12; i++ {
- aadhaar += strconv.Itoa(rng.Intn(10))
+ n, err := rand.Int(rand.Reader, big.NewInt(10))
+ if err != nil {
+ return ""
+ }
+ aadhaar += strconv.FormatInt(n.Int64(), 10)
}
+
+ // TODO: Add checksum validation
+ // Verhoeff algorithm is commonly used for Aadhaar number validation
+
return aadhaar
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| func GenerateAadhaarNumber() string { | |
| src := rand.NewSource(time.Now().UnixNano()) | |
| rng := rand.New(src) | |
| aadhaar := "" | |
| for i := 0; i < 12; i++ { | |
| aadhaar += strconv.Itoa(rng.Intn(10)) | |
| } | |
| return aadhaar | |
| } | |
| package adhar | |
| import ( | |
| "crypto/rand" | |
| "math/big" | |
| "strconv" | |
| ) | |
| func GenerateAadhaarNumber() string { | |
| aadhaar := "" | |
| for i := 0; i < 12; i++ { | |
| n, err := rand.Int(rand.Reader, big.NewInt(10)) | |
| if err != nil { | |
| return "" | |
| } | |
| aadhaar += strconv.FormatInt(n.Int64(), 10) | |
| } | |
| // TODO: Add checksum validation | |
| // Verhoeff algorithm is commonly used for Aadhaar number validation | |
| return aadhaar | |
| } |
| func GenerateRandomPAN() string { | ||
| var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
| var digits = "0123456789" | ||
| // Create a new source and random generator | ||
| src := rand.NewSource(time.Now().UnixNano()) | ||
| rng := rand.New(src) | ||
|
|
||
| // Generate first 5 letters | ||
| pan := "" | ||
| for i := 0; i < 5; i++ { | ||
| pan += string(letters[rng.Intn(len(letters))]) | ||
| } | ||
|
|
||
| // Generate 4 digits | ||
| for i := 0; i < 4; i++ { | ||
| pan += string(digits[rng.Intn(len(digits))]) | ||
| } | ||
|
|
||
| // Generate last letter | ||
| pan += string(letters[rng.Intn(len(letters))]) | ||
|
|
||
| return pan | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Enhance PAN number generation with validation and performance.
The current implementation has several areas for improvement:
- Use
strings.Builderfor efficient string concatenation. - Use
crypto/randinstead ofmath/randfor better security. - Add format validation for PAN number.
Apply this diff to improve the implementation:
import (
+ "crypto/rand"
- "math/rand"
+ "strings"
- "time"
)
func GenerateRandomPAN() string {
var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var digits = "0123456789"
- // Create a new source and random generator
- src := rand.NewSource(time.Now().UnixNano())
- rng := rand.New(src)
+ var builder strings.Builder
+ builder.Grow(10) // Pre-allocate capacity for 10 characters
+ // Helper function to get random character from string
+ getRandomChar := func(chars string) (byte, error) {
+ n, err := rand.Int(rand.Reader, big.NewInt(int64(len(chars))))
+ if err != nil {
+ return 0, err
+ }
+ return chars[n.Int64()], nil
+ }
// Generate first 5 letters
- pan := ""
for i := 0; i < 5; i++ {
- pan += string(letters[rng.Intn(len(letters))])
+ if c, err := getRandomChar(letters); err != nil {
+ return ""
+ } else {
+ builder.WriteByte(c)
+ }
}
// Generate 4 digits
for i := 0; i < 4; i++ {
- pan += string(digits[rng.Intn(len(digits))])
+ if c, err := getRandomChar(digits); err != nil {
+ return ""
+ } else {
+ builder.WriteByte(c)
+ }
}
// Generate last letter
- pan += string(letters[rng.Intn(len(letters))])
+ if c, err := getRandomChar(letters); err != nil {
+ return ""
+ } else {
+ builder.WriteByte(c)
+ }
- return pan
+ return builder.String()
}Committable suggestion skipped: line range outside the PR's diff.
| if languageID == "enin" { | ||
| aadhar_card := adhar.GenerateAadhaarNumber() | ||
| pan_card := pan.GenerateRandomPAN() | ||
| fmt.Printf("Adhar card: %s\n", aadhar_card) | ||
| fmt.Printf("Pan card: %s", pan_card) | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Fix inconsistent error handling and typo.
- Handle potential errors from
GenerateAadhaarNumberandGenerateRandomPAN. - Fix the typo in "Adhar" vs "Aadhaar".
Apply this diff to improve the implementation:
if languageID == "enin" {
aadhar_card := adhar.GenerateAadhaarNumber()
+ if aadhar_card == "" {
+ fmt.Println("Error generating Aadhaar number")
+ return
+ }
pan_card := pan.GenerateRandomPAN()
+ if pan_card == "" {
+ fmt.Println("Error generating PAN number")
+ return
+ }
- fmt.Printf("Adhar card: %s\n", aadhar_card)
+ fmt.Printf("Aadhaar card: %s\n", aadhar_card)
fmt.Printf("Pan card: %s", pan_card)
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if languageID == "enin" { | |
| aadhar_card := adhar.GenerateAadhaarNumber() | |
| pan_card := pan.GenerateRandomPAN() | |
| fmt.Printf("Adhar card: %s\n", aadhar_card) | |
| fmt.Printf("Pan card: %s", pan_card) | |
| } | |
| if languageID == "enin" { | |
| aadhar_card := adhar.GenerateAadhaarNumber() | |
| if aadhar_card == "" { | |
| fmt.Println("Error generating Aadhaar number") | |
| return | |
| } | |
| pan_card := pan.GenerateRandomPAN() | |
| if pan_card == "" { | |
| fmt.Println("Error generating PAN number") | |
| return | |
| } | |
| fmt.Printf("Aadhaar card: %s\n", aadhar_card) | |
| fmt.Printf("Pan card: %s", pan_card) | |
| } |
Summary by CodeRabbit