This is a Go program that generates unique codes, stores them in a PostgreSQL database, and can export the data to an Excel file. This project serves as a demonstration of my capabilities in Golang and database management.
- Generate unique codes with specified length
- Store generated codes in a PostgreSQL database
- Check the number of generated codes
- Export generated codes to an Excel file
- Clone the repository
git clone https://github.com/yourusername/unique-code-generator.git cd unique-code-generator
- Install dependencies
go get -u github.com/jmoiron/sqlx go get -u github.com/lib/pq go get -u github.com/xuri/excelize/v2
- Setup PostgreSQL database
CREATE DATABASE your_database_name; \c your_database_name CREATE TABLE generate_code ( id SERIAL PRIMARY KEY, code VARCHAR(12) UNIQUE NOT NULL );
- Run the program
go run main.go
- Generate Codes
- Enter the number of codes to generate
- Check Number of Generated Codes
- Displays the total number of codes generated so far
- Export to Excel
- Exports all generated codes to an Excel file (
./export/codes.xlsx
)
- Exports all generated codes to an Excel file (
Database configuration is prompted during runtime. The default values are:
- Host:
localhost
- Port:
5432
- User:
postgres
- Password: (empty)
- Database:
postgres
- main.go: Entry point of the application.
- generateCode: Generates unique codes and stores them in the database.
- getLenOfCode: Retrieves the number of generated codes from the database.
- downloadToExcel: Exports the generated codes to an Excel file.
- connectDB: Connects to the PostgreSQL database.
- initConfigDatabase: Initializes database configuration by prompting the user.
This project is licensed under the MIT License - see the LICENSE file for details.