Passed
Push — v3.0.0 ( 368635...9e91a1 )
by Serhii
01:21
created

langset.fileExists   A

Complexity

Conditions 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nop 1
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
package langset
2
3
import (
4
	"encoding/json"
5
	"errors"
6
	"log"
7
	"os"
8
)
9
10
func parseJsonIntoTrans(fileName string) *LangSet {
11
	content := getFileContent(fileName)
12
13
	var res LangSet
14
15
	err := json.Unmarshal(content, &res)
16
17
	if err != nil {
18
		log.Fatalln(err)
19
	}
20
21
	return &res
22
}
23
24
func getFileContent(filePath string) []byte {
25
	content, err := os.ReadFile(filePath)
26
27
	if err != nil {
28
		log.Fatalln(err)
29
	}
30
31
	return content
32
}
33
34
func fileExists(filePath string) (bool, error) {
35
	_, err := os.Stat(filePath)
36
37
	if err == nil {
38
		return true, nil
39
	}
40
41
	if errors.Is(err, os.ErrNotExist) {
42
		return false, nil
43
	}
44
45
	return false, err
46
}
47