-
Notifications
You must be signed in to change notification settings - Fork 7
/
generic.go
91 lines (79 loc) · 1.59 KB
/
generic.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package aiagent
import (
_ "embed"
"strconv"
"strings"
"syscall"
)
const (
_dot = "."
_linefeed = "\n" // linefeed
_linefeedR = '\n' // linefeed
_msgHeader = 2 // message header line
_err = " [error]"
_exit = " [exit]"
_dlinefeed = "\n\n"
_space = " "
_sep = ';'
_sep1 = ","
_sep2 = " / "
_unknownBody = "unknown -> invalid message body"
_unknownHeader = "unknown -> invalid message header"
)
//go:embed mandant.db
var db string
// getEnv ...
func getEnv(in string) (string, bool) {
return syscall.Getenv(in)
}
// bracket
func bracket(in string) string {
return "[" + in + "]"
}
// yesno ...
func yesno(state bool) string {
if state {
return "[yes]"
}
return "[no]"
}
// valid ...
func valid(state bool) string {
if state {
return "[valid]"
}
return "[failed]"
}
// validExit ...
func validExit(state bool) string {
if state {
return "[valid]"
}
return "[failed] [exit]"
}
// ctoa confidence float64 to ascii percentage
func ctoa(m *EMail) string {
var s strings.Builder
s.WriteString(strconv.Itoa(int(m.Local.Lang.Confidence*100)) + "% ")
if m.Local.Lang.Confidence < m.Local.TargetLangConfidence {
s.WriteString("[exit]")
} else {
s.WriteString("[valid]")
}
return s.String()
}
// itoa int to ascii
func itoa(in int) string {
return strconv.Itoa(in)
}
// price float to US$
func price(in float64) string {
return strconv.FormatFloat(in, 'f', 5, 64) + " US$ "
}
// isArray
func isArray(in []string) string {
if len(in) < 1 {
return "[none]"
}
return strings.Join(in, _sep1)
}