-
Notifications
You must be signed in to change notification settings - Fork 3
/
msg.go
executable file
·51 lines (43 loc) · 1.03 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
50
51
package jsonRespKit
import (
"github.com/richelieu-yang/chimera/v3/src/config/viperKit"
"github.com/richelieu-yang/chimera/v3/src/core/mapKit"
"github.com/richelieu-yang/chimera/v3/src/file/fileKit"
)
type FileData struct {
// Type 文件的类型,e.g. "properties"、"yaml"、"ini"...
Type string
// Data 文件的内容
Data []byte
}
/*
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.Type, nil, &m); err != nil {
return err
}
msgMap = mapKit.Merge(msgMap, m)
return nil
}