🍔 Burger King - Free Burger Code Generator 🍔
Generate a Burger King's promotion code to get a free burger using Golang.
$ go get github.com/scotow/burgoking
The library provides two ways to generate codes. A single code can be generating or an auto refreshing pool can be used.
func GenerateCode(meal *Meal) (code string, err error)
The meal
argument is used to fill the first page of the survey.
type Meal struct {
Restaurant int
Date time.Time
}
Passing nil
as an argument generate a random meal using the func RandomMeal() *Meal
function.
A pool of codes holds a fixed amount of codes. When a code of the pool is consumed by the function GetCode
, a new goroutine is spawned to generate a new code.
An expiration duration can be specified. When a code has stayed in the pool for too long, a timer removes it from the pool and a new generation is launched.
To create a new pool, you may call the following function:
func NewPool(size int, expiration, retry time.Duration) (pool *Pool, err error)
Where
size
is the total number of codes in the pool.expiration
is the duration required for a code to be remove and auto re-generated.retry
is the duration required between two calls of theGenerateCode
function if the first call failed for any reason. This prevents the pool from spaming the website.
The cmd folder contains three examples of program that use the burgoking
library.
The code command is a simple wrapper of the library. It generates a code and prints it to stdout
.
Here are the available options:
Usage of code:
-n int
number of code to generate (default 1)
-p
generate each code on a different goroutine (default false)
The api command starts a simple web server that returns a new promotion code to each request.
The web command is a ready-for-demo binary that serves a simple, yet beautiful UI generating promotion codes using a pool.
The program may setup a second private pool that requires a Authorization
HTTP header.
Here are the available options:
Usage of web:
-D string
private code expiration (default "24h0m0s")
-N int
private code pool size (default 1)
-R string
private code regeneration interval (default "30s")
-c string
contact address on error
-d string
public code expiration (default "24h0m0s")
-k string
authorization token for private and direct code (disable if empty)
-n int
public code pool size (default 3)
-p int
listening port (default 8080)
-r string
public code regeneration interval (default "30s")
Feedbacks are appreciated. Feel free to open an issue or a pull request if needed.
Furthermore, if you went to a restaurant which its number isn't in the restaurants list, a merge request to add it is appreciated.
burgoking provided by Scotow is for illustrative purposes only which provides customers with programming information regarding the products. This software is supplied "AS IS" without any warranties and support.
I assumes no responsibility or liability for the use of the software, conveys no license or title under any patent, copyright, or mask work right to the product.
A deprecated and no more maintained version of this project made with JavaScript (NodeJS) and CasperJS is availiable here.
Enjoy your meal!