This repository was archived by the owner on Feb 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathendpoint.go
More file actions
62 lines (50 loc) · 1.22 KB
/
endpoint.go
File metadata and controls
62 lines (50 loc) · 1.22 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
package ot
import (
"errors"
"fmt"
"strings"
"github.com/itcomusic/ot/internal/conn"
)
var (
// errServiceMethod returned by invalid service method.
errServiceMethod = errors.New("ot: service/method requester ill-formed")
)
var (
defaultPort = ":2099"
)
// Endpoint represents connection address.
type Endpoint struct {
dialer conn.Dialer
}
// NewEndpoint creates information about connection to the server opentext. No creates connection to server.
func NewEndpoint(addr string) *Endpoint {
if !strings.Contains(addr, ":") {
addr += defaultPort
}
return &Endpoint{dialer: &conn.Dial{Addr: addr}}
}
// User creates new session with auth authentication.
func (e *Endpoint) User(username, password string) *Session {
return &Session{
ep: e,
auth: &auth{enc: fmt.Sprintf("'_UserName'='%s','_UserPassword'='%s'", username, password)},
}
}
// Token creates new session with token authentication.
func (e *Endpoint) Token(token string) *Session {
return &Session{
ep: e,
auth: &auth{enc: fmt.Sprintf("'_Cookie'='%s'", token)},
}
}
// dial using for tests.
func (e Endpoint) dial(d conn.Dialer) *Endpoint {
e.dialer = d
return &e
}
type auth struct {
enc string
}
func (u *auth) String() string {
return u.enc
}