-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.go
68 lines (50 loc) · 1.27 KB
/
service.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
// Package foliogo provides a client library for the FOLIO LMS
package foliogo
import "os"
import "github.com/MikeTaylor/catlogger"
type Service struct {
url string
logger *catlogger.Logger
}
func (this Service)String() string {
return "SERVICE(" + this.url + ")"
}
func NewService(url string, optLogger ...*catlogger.Logger) Service {
var logger *catlogger.Logger
if (len(optLogger) > 0 && optLogger[0] != nil) {
logger = optLogger[0]
} else {
logcat := os.Getenv("LOGGING_CATEGORIES")
if (logcat == "") {
logcat = os.Getenv("LOGCAT")
}
logger = catlogger.MakeLogger(logcat, "", false)
}
s := Service{
url: url,
logger: logger,
}
s.Log("service", "Made new service on URL", url)
return s
}
func (this Service)Log(cat string, args ...string) {
this.logger.Log(cat, args...)
}
func (this Service)Login(tenant string, username string, password string) (Session, error) {
session, err := NewSession(this, tenant, username, password)
if err != nil {
return Session{}, err
}
err = session.Login()
if err != nil {
return Session{}, err
}
return session, nil
}
func (this Service)ResumeSession(tenant string) (Session, error) {
session, err := NewSession(this, tenant, "", "NOPASS")
if err != nil {
return Session{}, err
}
return session, nil
}