timeago.isFilePresent   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
dl 0
loc 11
rs 10
c 0
b 0
f 0
nop 1
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