-
Notifications
You must be signed in to change notification settings - Fork 0
/
caller.go
executable file
·60 lines (52 loc) · 1.24 KB
/
caller.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
52
53
54
55
56
57
58
59
60
package muses
import (
"io/ioutil"
"reflect"
"github.com/yitume/muses/pkg/common"
)
// 通过反射取包里面的值
var orderCallerList = []callerAttr{
{common.ModAppName},
{common.ModLoggerName},
{common.ModPromName},
{common.ModMysqlName},
{common.ModRedisName},
{common.ModMongoName},
{common.ModGinSessionName},
{common.ModEchoSessionName},
{common.ModTplBeegoName},
{common.ModStatName},
{common.ModGinName},
}
type callerAttr struct {
Name string
}
// Container from file.
func parseFile(path string) ([]byte, error) {
// read file to []byte
b, err := ioutil.ReadFile(path)
if err != nil {
return b, err
}
return b, nil
}
func sortCallers(callers []common.CallerFunc) (callerSort []common.Caller, err error) {
callerMap := make(map[string]common.Caller)
callerSort = make([]common.Caller, 0)
for _, caller := range callers {
obj := caller()
name := getCallerName(obj)
callerMap[name] = obj
}
for _, value := range orderCallerList {
caller, ok := callerMap[value.Name]
if ok {
// 如果存在于map,加入到排序里的caller sort
callerSort = append(callerSort, caller)
}
}
return
}
func getCallerName(caller common.Caller) string {
return reflect.ValueOf(caller).Elem().FieldByName("Name").String()
}