Passed
Push — v3.0.0 ( e8e2e8...c00ed6 )
by Serhii
01:27
created

timeago.newLangSet   A

Complexity

Conditions 3

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
dl 0
loc 17
rs 9.9
c 0
b 0
f 0
nop 0
1
package timeago
2
3
import (
4
	"fmt"
5
	"path"
6
	"runtime"
7
)
8
9
type LangForms map[string]string
10
11
type LangSet struct {
12
	Lang    string    `json:"lang"`
13
	Format  string    `json:"format"`
14
	Ago     string    `json:"ago"`
15
	Online  string    `json:"online"`
16
	JustNow string    `json:"justnow"`
17
	Second  LangForms `json:"second"`
18
	Minute  LangForms `json:"minute"`
19
	Hour    LangForms `json:"hour"`
20
	Day     LangForms `json:"day"`
21
	Week    LangForms `json:"week"`
22
	Month   LangForms `json:"month"`
23
	Year    LangForms `json:"year"`
24
}
25
26
func newLangSet() (*LangSet, error) {
27
	_, filename, _, ok := runtime.Caller(0)
28
29
	if !ok {
30
		return nil, createError("No called information")
31
	}
32
33
	rootPath := path.Dir(filename)
34
	filePath := fmt.Sprintf(rootPath+"/langs/%s.json", conf.Language)
35
36
	if cache, ok := cachedJsonRes[filePath]; ok {
37
		return cache, nil
38
	}
39
40
	cachedJsonRes[filePath] = parseLangSet(filePath)
41
42
	return cachedJsonRes[filePath], nil
43
}
44