summaryrefslogtreecommitdiff
path: root/common/common.go
blob: 20c2c0abc0005703b283dd14bbfb9844ac9e2a5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package common

import (
	"os"
	"fmt"
	"strconv"
)

func Perror(function string, err error) error {
	return fmt.Errorf("%s(): %w", function, err)
}

func Error(format string, a ... any) (int, error) {
	fmt.Fprintf(os.Stderr, "error: ")
	if (len(a) == 0) {
		return fmt.Fprintf(os.Stderr, format)
	} else {
		return fmt.Fprintf(os.Stderr, format, a)
	}
}

func Intify(s string) (int, error) {
	i, err := strconv.ParseInt(s, 0, 0)
	return int(i), err
}