-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.go
More file actions
121 lines (93 loc) · 3.01 KB
/
main.go
File metadata and controls
121 lines (93 loc) · 3.01 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// mirth-api project main.go
package main
import (
"flag"
"fmt"
"os"
"github.com/NavigatingCancer/mirth-api/mirthagent"
"github.com/NavigatingCancer/mirth-api/mirthagent/errors"
"github.com/caimeo/console"
"github.com/caimeo/iniflags"
)
var remoteServer = flag.String("server", "localhost", "The remote server name")
var remotePort = flag.String("port", "40443", "The remote server port")
var remoteAPIVersion = flag.String("api_version", "3.5.0", "The remote Mirth server API version")
var remoteUsername = flag.String("username", "", "The remote user name")
var remotePassword = flag.String("password", "", "The remote password")
var tlsVerify = flag.Bool("tls", true, "Is TLS verfify on")
var verboseMode = flag.Bool("verbose", false, "Verbose console output.")
var debugMode = flag.Bool("debug", false, "Debug console output.")
var con *console.Console
func main() {
iniflags.SetConfigFile(".settings")
iniflags.SetAllowMissingConfigFile(true)
iniflags.Parse()
//setup output
go monitorErrors(errors.CommonErrorChannel())
con := console.Init(*verboseMode, *debugMode)
errors.Console = con
con.Always("Mirth API")
//setup MirthAgent
mirthagent.TLSVerify = *tlsVerify
a := mirthagent.New(*remoteServer, *remotePort, *remoteAPIVersion)
//get the current status
_, _, isRestoreable := a.LoginStatus()
isConnected := false
if isRestoreable {
connectCh, _ := a.Connect()
isConnected, _ = <-connectCh
}
if isConnected {
con.Verbose("Connection Restored: ", isConnected)
} else {
if len(*remoteUsername) > 0 && len(*remotePassword) > 0 {
loginCh, _ := a.Login(*remoteUsername, *remotePassword)
isConnected, _ = <-loginCh
if isConnected {
con.Verbose("Connection New: ", isConnected)
}
} else {
con.Always("Cannot connect, user name and password required.")
os.Exit(1)
}
}
if isConnected {
con.Verbose("Ready")
con.Debug(a.LoginStatus())
} else {
con.Always("Cannot connect")
os.Exit(2)
}
rc, _ := a.API.Server.ResourcesList()
r := <-rc
// cg := model.ChannelGroup{Versionø: "3.5.0", Idø: "b49f7831-d524-4a02-bb8c-61db3921166b", Nameø: "TEST Name", Descriptionø: "This is the description"}
// c1 := model.ChannelGroupChannel{Versionø: "3.5.0", Idø: "abc"}
// c2 := model.ChannelGroupChannel{Versionø: "3.5.0", Idø: "xyz"}
// cg.AppendChannel(c1)
// cg.AppendChannel(c2)
// cg.SetName("A different name")
// cg.SetChannels(append(cg.Channels(), c2))
// console.Always(cg)
//x, _ := xml.Marshal(cg)
console.Always(len(r))
x := r[0].Id
console.Always("- - - - -")
console.Always(string(x))
console.Always("---------")
fc, _ := a.API.Server.SetDefaultResourceDirectory("/mnt/mirth/data/java")
f := <-fc
console.Always("xxx- - - - -")
console.Always(f)
console.Always("---------")
// time.Sleep(5 * time.Second)
}
func monitorErrors(e chan error) {
for err := range e {
x, ok := interface{}(err).(errors.ExtendedError)
if ok {
fmt.Fprintln(os.Stderr, "EXTENDED ERROR\n", err, "\n", x.Cause())
} else {
fmt.Fprintln(os.Stderr, "ERROR\n", err)
}
}
}