Total Lines | 47 |
Duplicated Lines | 0 % |
Changes | 0 |
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 |