-
Notifications
You must be signed in to change notification settings - Fork 1
/
io.go
58 lines (49 loc) · 991 Bytes
/
io.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
package opnborg
import (
"encoding/xml"
"os"
"sync"
)
//
// Display IO
//
// outSlice write messages to stdout
func outSlice(msg []byte, config *OPNCall) {
os.Stdout.Write([]byte(config.AppName))
os.Stdout.Write(msg)
os.Stdout.Write([]byte("\n"))
}
// displayChan channel for the display engine
var displayChan, display, wg = make(chan []byte, 20), sync.WaitGroup{}, sync.WaitGroup{}
// startLog is a non-blocking, conditional, concurrent-save background output handler
func startLog(config *OPNCall) {
go func() {
for msg := range displayChan {
outSlice(msg, config)
}
display.Done()
}()
}
//
// Little Helper
//
// isEnv
func isEnv(check string) bool {
if content, ok := os.LookupEnv(check); ok {
if content != "" {
return true
}
}
return false
}
// isValidXML
func isValidXML(s string) bool {
return xml.Unmarshal([]byte(s), new(interface{})) == nil
}
// padMonth
func padMonth(in string) string {
if len(in) == 1 {
return "0" + in
}
return in
}