Skip to content

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.

Notifications You must be signed in to change notification settings

nanwp/generate-code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unique Code Generator

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.

Features

  • 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

Requirements

  • Go 1.16+
  • PostgreSQL
  • excelize Go library for Excel operations
  • sqlx Go library for SQL operations

Installation

  1. Clone the repository
    git clone https://github.com/yourusername/unique-code-generator.git
    cd unique-code-generator
  2. Install dependencies
    go get -u github.com/jmoiron/sqlx
    go get -u github.com/lib/pq
    go get -u github.com/xuri/excelize/v2
  3. 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
    );
  4. Run the program
    go run main.go

Usage

  1. Generate Codes
    • Enter the number of codes to generate
  2. Check Number of Generated Codes
    • Displays the total number of codes generated so far
  3. Export to Excel
    • Exports all generated codes to an Excel file (./export/codes.xlsx)

Configuration

Database configuration is prompted during runtime. The default values are:

  • Host: localhost
  • Port: 5432
  • User: postgres
  • Password: (empty)
  • Database: postgres

Code Overview

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

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages