Passed
Push — main ( 3ec306...c5cfaa )
by Yume
01:53 queued 44s
created

utils.GetSecretKey   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
package utils
2
3
import (
4
	"strconv"
5
6
	"github.com/pkg/errors"
7
	"github.com/uptrace/opentelemetry-go-extra/otelzap"
8
	"go.uber.org/zap"
9
)
10
11
const (
12
	base10  = 10
13
	bitSize = 32
14
)
15
16
// ConvertStrToUInt converts a string to an unsigned integer
17
func ConvertStrToUInt(str string) (uint, error) {
18
	number, err := strconv.ParseUint(str, base10, bitSize)
19
	if err != nil {
20
		otelzap.L().Error("Error while converting string to uint", zap.Error(err))
21
		return 0, errors.New("Error while converting string to uint")
22
	}
23
	return uint(number), nil
24
}
25
26
// ConvertUIntToStr converts an unsigned integer to a string
27
func ConvertUIntToStr(number uint) string {
28
	return strconv.FormatUint(uint64(number), base10)
29
}
30
31
// ConvertStrToInt converts a string to an integer
32
func ConvertStrToInt(str string) (int, error) {
33
	number, err := strconv.ParseInt(str, base10, bitSize)
34
	if err != nil {
35
		otelzap.L().Error("Error while converting string to int", zap.Error(err))
36
		return 0, errors.New("Error while converting string to int")
37
	}
38
	return int(number), nil
39
}
40