package main

import (
	"golang.source-fellows.com/pattern/circuitbreaker/internal"
	"golang.source-fellows.com/pattern/circuitbreaker/internal/http"
	"log"
	"time"
)

func main() {

	realProvider := http.NewPaymentServiceProvider()
	decorator := http.NewCircuitBreakerDecorator(realProvider)

	var transactionResult internal.TxResult
	var err error
	success := false
	for !success {
		customer := internal.CustomerData{}
		transactionResult, err = decorator.RequestPayment(10.0, customer)
		if err == nil {
			success = true
		} else {
			log.Println("error in loop", err)
			time.Sleep(1 * time.Second)
		}
	}
	log.Printf("transaction successfull %+v", transactionResult)
}
