Giter Club home page Giter Club logo

go-quick-serial's Introduction

Go-QuickSerial

Lightweight and efficient Go package for generating unique serial codes

Go-QuickSerial is designed to help you generate unique serial codes with customizable patterns, prefixes, suffixes, and character sets. Ideal for applications like vouchers, product keys, and access codes, Go-QuickSerial ensures each generated code is unique and secure.

Features

  • Customizable Patterns: Define your own patterns with placeholders for random characters.
  • Configurable Prefixes and Suffixes: Add static text before or after the generated code.
  • Multiple Character Sets: Choose from alphanumeric, alphabetic, or numeric character sets.
  • Batch Generation: Generate multiple unique codes concurrently.
  • Concurrency Support: Efficiently generate codes using Go's concurrency features.

Installation

Install the package using the following command:

go get -u github.com/rayrizqie/go-quick-serial

Usage

Config Reference

  • Pattern (string): Defines the pattern for the serial code. Use # as a placeholder for random characters. Example: "##-##-##".

  • Prefix (string): A static prefix added before the generated code. Example: "PRE-".

  • Suffix (string): A static suffix added after the generated code. Example: "-SUF".

  • Charset (Charset): Defines the character set used for generating random characters. Available options:

    • AlphanumericCharset{}: Uses uppercase letters and digits.
    • AlphabetCharset{}: Uses uppercase letters only.
    • NumberCharset{}: Uses digits only.

Generating a Single Serial Code

package main

import (
    "fmt"
    "log"
    serialize "github.com/rayrizqie/go-quick-serial"
)

func main() {
    config := serialize.SerialCodeConfig{
        Pattern: "##-##-##",
        Prefix:  "PRE-",
        Suffix:  "-SUF",
        Charset: serialize.AlphanumericCharset{},
    }

    generator := serialize.SerialCodeGenerator{
        Validator: serialize.PatternValidator{},
    }

    // Generate a single serial code
    serialCode, err := generator.Generate(config)
    if err != nil {
        log.Fatalf("Error generating serial code: %v", err)
    }
    fmt.Printf("Generated Serial Code: %s\n", serialCode)
}

Generating a Batch of Serial Codes

package main

import (
    "fmt"
    "log"
    serialize "github.com/rayrizqie/go-quick-serial"
)

func main() {
    config := serialize.SerialCodeConfig{
        Pattern: "##-##-##",
        Prefix:  "PRE-",
        Suffix:  "-SUF",
        Charset: serialize.AlphanumericCharset{},
    }

    generator := serialize.SerialCodeGenerator{
        Validator: serialize.PatternValidator{},
    }

    // Generate a batch of serial codes
    batchCount := 5
    serialCodes, err := generator.GenerateBatch(config, batchCount)
    if err != nil {
        log.Fatalf("Error generating batch of serial codes: %v", err)
    }
    fmt.Printf("Generated Batch of Serial Codes: %v\n", serialCodes)
}

Example Project

An example project is included in the example directory to demonstrate how to use the package.

To run the examples, navigate to the example directory and use the go run command:

License

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

Contributing

Contributions are welcome! Please open an issue or submit a pull request with your improvements.

go-quick-serial's People

Contributors

rayrizqie avatar

Watchers

 avatar

go-quick-serial's Issues

Performance Benchmarking

We need to benchmark the current code to understand its performance characteristics.

The goal is to identify any bottlenecks or inefficiencies in the code generation logic and optimize it for better performance if necessary.

Custom Character Sets

Allow users to define their own custom character sets.

Example: CustomCharset{Characters: "ABCDEF012345"}.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.