package main

import (
	"fmt"
	"math/rand"
	"os"
)

var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")

func RandString(n int) string {
	b := make([]rune, n)
	for i := range b {
		b[i] = letters[rand.Intn(len(letters))]
	}
	return string(b)
}

func errCheck(err error, msg string, opts ...interface{}) {
	if err != nil {
		fmt.Errorf(msg + "\n", opts...)
		fmt.Errorf(err.Error())
	}
}

func errCheckExit(err error, msg string, opts ...interface{}) {
	if err != nil {
		fmt.Errorf(msg + "\n", opts...)
		fmt.Errorf(err.Error())
		os.Exit(1)
	}
}

func errCheckPanic(err error, msg string, opts ...interface{}) {
	if err != nil {
		panic(fmt.Sprintf(msg + "\n", opts...) + err.Error())
	}
}


func logPanic() {
	if r := recover(); r!= nil {
		fmt.Errorf("%s\n", r)
	}
}