Giter VIP home page Giter VIP logo

vouchercodegenerator's Introduction

Voucher Code Generator

Generate unique, random, and hard to guess coupon / voucher codes. Use cases: promo codes, loyalty coupons, gift vouchers, in-app purchases, referral links

Instalation

Just use go get.

    go get github.com/AmirSoleimani/VoucherCodeGenerator/vcgen

Sample

func main() {

	// lolipop :P
	wg := sync.WaitGroup{}
	wg.Add(3)

	// normal
	go func(wg *sync.WaitGroup) {
		vc := vcgen.New(&vcgen.Generator{Count: 10, Pattern: "###-###-###", Charset: "123456789"})
		result, err := vc.Run()
		if err != nil {
			fmt.Println(err)
		}
		fmt.Println(result)
		wg.Done()
	}(&wg)

	// with prefix
	go func(wg *sync.WaitGroup) {
		vcPrefix := vcgen.New(&vcgen.Generator{Count: 10, Pattern: "######", Prefix: "WELC-"})
		result, err := vcPrefix.Run()
		if err != nil {
			fmt.Println(err)
		}
		fmt.Println(result)
		wg.Done()
	}(&wg)

	// with prefix + postfix
	go func(wg *sync.WaitGroup) {
		vcPrePostfix := vcgen.New(&vcgen.Generator{Count: 10, Pattern: "######", Prefix: "WELC-", Postfix: "-B"})
		result, err := vcPrePostfix.Run()
		if err != nil {
			fmt.Println(err)
		}
		fmt.Println(result)
		wg.Done()
	}(&wg)

	wg.Wait()

}

Prefix and Postfix

You can optionally surround each generated code with a prefix and/or postfix.

Pattern

Codes may follow a specified pattern. Use hash (#) as a placeholder for random characters.

Infeasible configs

There exist some configs that are not feasible. For example it's not possible to generate 1000 codes if you want your codes to be 2 characters long and consisting only of numbers. Voucher code generator detects such cases and throws an error "Not possible to generate requested number of codes.".

Config reference

attribute default value description
length 6 Number of characters in a generated code (excluding prefix and postfix)
count 1 Number of codes generated.
charset alphanumeric Characters that can appear in the code.
prefix "" A text appended before the code.
postfix "" A text appended after the code.
pattern "######" A pattern for codes where hashes (#) will be replaced with random characters.

License

Code released under the MIT license.

vouchercodegenerator's People

Contributors

amirsoleimani avatar

Watchers

James Cloos avatar

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.