Documentation ¶
Overview ¶
Pay as you Go library to scheduler deduct user's wallet balance every X seconds
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Item struct { Every int DoFunc func(option ItemOption) bool // contains filtered or unexported fields }
Create a new scheduler by setting how many every seconds jobs run and function to get user wallet balance and function to set user wallet balance (if return be false, job will removed)
func New ¶
Create a new pay as you go with creating a new scheduler
Example ¶
package main import ( "fmt" payg "github.com/iamnonroot/pay-as-you-go" ) func main() { var wallets map[string]int = map[string]int{ "root": 1000, "user": 10000, } item := payg.New(&payg.Item{ Every: 3, DoFunc: func(option payg.ItemOption) bool { balance := wallets[option.Wallet] if balance-option.Price < 0 { return false } wallets[option.Wallet] = balance - option.Price fmt.Println(wallets[option.Wallet]) return true }, }) item.Add(payg.ItemOption{ UUID: "root-going", Wallet: "root", Price: 400, }) item.Add(payg.ItemOption{ UUID: "user-going", Wallet: "user", Price: 6000, }) item.Start() }
Output:
func (*Item) Add ¶
func (item *Item) Add(option ItemOption)
Add a new scheduler job with a UUID and do it for every X seconds and a function to do
type ItemOption ¶
Create new scheduler job by setting a unique name/id for job and user wallet id and price of product
Click to show internal directories.
Click to hide internal directories.