utils.go   A
last analyzed

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 28
dl 0
loc 47
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A timeago.isFilePresent 0 11 3
A timeago.unixToTime 0 2 1
A timeago.parseLangSet 0 11 2
A timeago.readFile 0 7 2
1
package timeago
2
3
import (
4
	"encoding/json"
5
	"errors"
6
	"log"
7
	"os"
8
	"time"
9
)
10
11
func unixToTime(userDate int) time.Time {
12
	return time.Unix(int64(userDate), 0)
13
}
14
15
func parseLangSet(fileName string) *LangSet {
16
	content := readFile(fileName)
17
18
	var res LangSet
19
20
	err := json.Unmarshal(content, &res)
21
	if err != nil {
22
		log.Fatalln(err)
23
	}
24
25
	return &res
26
}
27
28
func readFile(filePath string) []byte {
29
	content, err := os.ReadFile(filePath)
30
	if err != nil {
31
		log.Fatalln(err)
32
	}
33
34
	return content
35
}
36
37
func isFilePresent(filePath string) (bool, error) {
38
	_, err := os.Stat(filePath)
39
	if err == nil {
40
		return true, nil
41
	}
42
43
	if errors.Is(err, os.ErrNotExist) {
44
		return false, nil
45
	}
46
47
	return false, err
48
}
49