Skip to content

Adds a new feature to generate aadhar card and pan card for enin#20

Open
nikultaka wants to merge 4 commits intodevelopfrom
feature/29-generate-person-mock-for-indian-english
Open

Adds a new feature to generate aadhar card and pan card for enin#20
nikultaka wants to merge 4 commits intodevelopfrom
feature/29-generate-person-mock-for-indian-english

Conversation

@nikultaka
Copy link
Copy Markdown
Contributor

@nikultaka nikultaka commented Feb 11, 2025

Summary by CodeRabbit

  • New Features
    • Added interactive language selection for mock data generation. When a specific language is chosen, the system now also produces random identification numbers.
    • Expanded the mock data library with comprehensive datasets covering addresses (cities, states, streets, ZIP codes), personal names (male, female, and last names), gender identities, and phone area codes.
    • Introduced a randomized data registration mechanism that assembles diverse and realistic sample content.
    • Added system feedback that logs the active language setting for enhanced transparency.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 11, 2025

Walkthrough

The pull request updates mock data generation by enhancing the GenerateMockExample function. It removes a hardcoded language parameter and adds user input for dynamic language selection with a special branch for "enin" that triggers Aadhaar and PAN number generation. Additionally, several new mock data packages have been introduced for addresses, names, genders, and phone area codes. A new translation package registers randomized mock data and logs the set language, and separate generator functions have been added to create random Aadhaar and PAN numbers.

Changes

File(s) Change Summary
examples/mock_example.go Updated GenerateMockExample: removed hardcoded "ptbr", added user prompt for language input, and conditionally generates Aadhaar and PAN when language is "enin".
pkg/mocai/entities/address/mocks/enin/cities.go, .../states.go, .../streets.go, .../zip_codes.go Introduced new enin mock data for Indian addresses: cities (200 names), states, streets (200 names), and ZIP codes (200 codes).
pkg/mocai/entities/gender/mocks/enin/genders.go Added Genders variable listing various gender identities.
pkg/mocai/entities/person/mocks/enin/first_names_female.go, .../first_names_male.go, .../last_names.go Added mock variables for Indian first names (female & male) and last names (300 names).
pkg/mocai/entities/phone/mocks/enin/area_codes.go Added a new mock variable for Brazilian telephone area codes.
pkg/mocai/translations/en_in.go, pkg/mocai/translations/translations.go Introduced a new translation package with an init function to register randomized mock data and updated SetLanguage with a log print.
pkg/mocai/entities/adhar/generator.go Added GenerateAadhaarNumber: a function to generate a random 12-digit Aadhaar number.
pkg/mocai/entities/pan/generator.go Added GenerateRandomPAN: a function to produce a random PAN (5 uppercase letters, 4 digits, 1 uppercase letter).

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
Loading

Possibly related PRs

Suggested reviewers

  • DODOSUBI
  • rluders
  • nikunjxforia

Poem

I'm a rabbit in a code field so bright,
Hopping through mocks and data with delight.
Aadhaar and PAN numbers dance in a line,
New translations and names all perfectly align.
With every line, my whiskers twitch in glee!
🐰 Hop on, code friends—celebration for you and me!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Genders variable 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:

  1. Are exactly 6 digits
  2. Follow the Indian postal service format
  3. 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:

  1. States "200 distinct cities" but contains 227 cities
  2. 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

📥 Commits

Reviewing files that changed from the base of the PR and between ee39394 and 11e2051.

📒 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.

Comment on lines +9 to +18
// 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
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Fix deprecated rand.Seed usage and enhance Aadhaar validation.

The function has the following issues:

  1. Uses deprecated rand.Seed function.
  2. 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.

Suggested change
// 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)

Comment on lines +20 to +41
// 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
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Fix deprecated rand.Seed usage and enhance PAN validation.

The function has the following issues:

  1. Uses deprecated rand.Seed function.
  2. 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:

  1. First character: Letter category (P for Individual, C for Company, etc.)
  2. Next three characters: Name-based sequence
  3. 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.

Suggested change
// 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)

Comment on lines +12 to +27
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))],
})
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

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.

Suggested change
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))],
})
}

Comment on lines +15 to +19
// set the language
var languageID string
fmt.Print("Enter your language : ")
fmt.Scan(&languageID)
translations.SetLanguage(languageID) //test for : ptbr,enin
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ 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.

Suggested change
// 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)

Comment on lines +4 to +227
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",
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

@@ -0,0 +1,44 @@
package helper
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the update, sure, i will put that helper file under the folder "generator"

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 26aff36 and 78fcac5.

📒 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.

Comment on lines +10 to +19
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
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance Aadhaar number generation with validation and security.

The current implementation has several areas for improvement:

  1. Add format validation for the 12-digit Aadhaar number.
  2. Implement checksum validation.
  3. Use crypto/rand instead of math/rand for 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.

Suggested change
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
}

Comment on lines +9 to +31
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
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance PAN number generation with validation and performance.

The current implementation has several areas for improvement:

  1. Use strings.Builder for efficient string concatenation.
  2. Use crypto/rand instead of math/rand for better security.
  3. 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.

Comment on lines +47 to +52
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)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Fix inconsistent error handling and typo.

  1. Handle potential errors from GenerateAadhaarNumber and GenerateRandomPAN.
  2. 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.

Suggested change
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)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants