This repository was archived by the owner on Dec 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapabilities.go
More file actions
executable file
·73 lines (57 loc) · 1.61 KB
/
capabilities.go
File metadata and controls
executable file
·73 lines (57 loc) · 1.61 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
// capabilities
package rets
import (
"errors"
"github.com/mlapping/rets/results"
"regexp"
)
type Capabilities struct {
Host string
GetObject string
GetMetadata string
Login string
Logout string
Search string
}
func (cap *Capabilities) setFromLogin(reply *results.LoginReply) error {
rMetadata := regexp.MustCompile(`GetMetadata=([^\s]+)`)
rObject := regexp.MustCompile(`GetObject=([^\s]+)`)
rSearch := regexp.MustCompile(`Search=([^\s]+)`)
rLogout := regexp.MustCompile(`Logout=([^\s]+)`)
cap.GetObject = rObject.FindStringSubmatch(reply.Response.Text)[1]
cap.GetMetadata = rMetadata.FindStringSubmatch(reply.Response.Text)[1]
cap.Search = rSearch.FindStringSubmatch(reply.Response.Text)[1]
cap.Logout = rLogout.FindStringSubmatch(reply.Response.Text)[1]
return cap.Validate()
}
func (cap *Capabilities) Validate() error {
errPrefix := "Server did not return valid capabilities for: "
if cap.GetObject == "" {
return errors.New(errPrefix + "GetObject")
}
if cap.GetMetadata == "" {
return errors.New(errPrefix + "GetMetadata")
}
if cap.Search == "" {
return errors.New(errPrefix + "Search")
}
if cap.Logout == "" {
return errors.New(errPrefix + "Logout")
}
return nil
}
func (cap *Capabilities) LoginUrl() string {
return cap.Host + cap.Login
}
func (cap *Capabilities) GetObjectUrl() string {
return cap.Host + cap.GetObject
}
func (cap *Capabilities) MetadataUrl() string {
return cap.Host + cap.GetMetadata
}
func (cap *Capabilities) LogoutUrl() string {
return cap.Host + cap.Logout
}
func (cap *Capabilities) SearchUrl() string {
return cap.Host + cap.Search
}