-
Notifications
You must be signed in to change notification settings - Fork 42
/
helpers.go
71 lines (61 loc) · 1.42 KB
/
helpers.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
61
62
63
64
65
66
67
68
69
70
71
package syslutil
import (
"strings"
sysl "github.com/anz-bank/sysl/pkg/sysl"
"github.com/sirupsen/logrus"
)
// LogLevels ...
// nolint:gochecknoglobals
var LogLevels = map[string]logrus.Level{
"": logrus.ErrorLevel,
"off": logrus.ErrorLevel,
"debug": logrus.DebugLevel,
"info": logrus.InfoLevel,
"warn": logrus.WarnLevel,
"trace": logrus.TraceLevel,
}
func SetLogLevel(level string) {
if level, has := LogLevels[level]; has {
logrus.SetLevel(level)
}
}
func CleanAppName(name string) string {
parts := strings.Split(name, "::")
for i := range parts {
parts[i] = strings.TrimSpace(parts[i])
}
return GetAppName(&sysl.AppName{Part: parts})
}
func GetAppName(appname *sysl.AppName) string {
return JoinAppName(appname)
}
func GetApp(appName *sysl.AppName, mod *sysl.Module) *sysl.Application {
return mod.Apps[GetAppName(appName)]
}
func HasPattern(attrs map[string]*sysl.Attribute, pattern string) bool {
patterns, has := attrs["patterns"]
if has {
if x := patterns.GetA(); x != nil {
for _, y := range x.Elt {
if y.GetS() == pattern {
return true
}
}
}
}
return false
}
func IsSameApp(a *sysl.AppName, b *sysl.AppName) bool {
if len(a.Part) != len(b.Part) {
return false
}
for i := range a.Part {
if a.Part[i] != b.Part[i] {
return false
}
}
return true
}
func IsSameCall(a *sysl.Call, b *sysl.Call) bool {
return IsSameApp(a.Target, b.Target) && a.Endpoint == b.Endpoint
}