-
Notifications
You must be signed in to change notification settings - Fork 3
/
msg.go
executable file
·49 lines (42 loc) · 1.02 KB
/
msg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package jsonRespKit
import (
"github.com/richelieu-yang/chimera/v2/src/config/viperKit"
"github.com/richelieu-yang/chimera/v2/src/core/fileKit"
"github.com/richelieu-yang/chimera/v2/src/core/mapKit"
)
type FileData struct {
Data []byte
// FileType 文件的类型,e.g. "properties"、"yaml"、"ini"...
FileType string
}
/*
key: code
value: message
*/
var msgMap = make(map[string]string)
// readFile 读取message文件,加到 msgMap 中.
/*
@param filePath 建议是 .properties 的文件
*/
func readFile(filePath string) error {
if err := fileKit.AssertExistAndIsFile(filePath); err != nil {
return err
}
m := make(map[string]string)
if _, err := viperKit.UnmarshalFromFile(filePath, nil, &m); err != nil {
return err
}
msgMap = mapKit.Merge(msgMap, m)
return nil
}
func readFileData(fd *FileData) error {
if fd == nil {
return nil
}
m := make(map[string]string)
if _, err := viperKit.Unmarshal(fd.Data, fd.FileType, nil, &m); err != nil {
return err
}
msgMap = mapKit.Merge(msgMap, m)
return nil
}