package errutil

import (
	"fmt"
	"os"
	"sync/atomic"
	fileutil "tiloader/pkg/fileutil"
)

var errorCount int64 = 0
var cfg fileutil.ConfigFile

func Init(cfgFile fileutil.ConfigFile) {
	cfg = cfgFile
	atomic.StoreInt64(&errorCount, 0)
}

func ErrCtl() {
	atomic.AddInt64(&errorCount, 1)

	if errorCount > int64(cfg.MaxError) {
		fmt.Println("error count more than max-error:", int64(cfg.MaxError))
		os.Exit(2)
	}
}
