This repository has been archived by the owner on Mar 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathclient.go
140 lines (113 loc) · 4.39 KB
/
client.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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*** Copyright (c) 2016, The BioTeam, Inc. ***
*** For more information please refer to the LICENSE.md file ***/
package gorods
// #include "wrapper.h"
import "C"
import (
"fmt"
// "io/ioutil"
// "path/filepath"
// "strconv"
// "strings"
// "time"
// "unsafe"
)
// Client structs are used to store connection options, and instatiate connections with those options
type Client struct {
Options *ConnectionOptions
ConnectErr error
}
// OpenCollection will create a new connection using the previously configured iRODS client. It will execute the handler,
// and close *Collection and *Collection automatically when your handler finishes execution.
// Operations on a single connection are queued when shared between goroutines (iRODS C API
// doesn't support concurrent operations on a single connection), so be sure to open up new connections
// for long-running operations to prevent blocking between goroutines.
func (cli *Client) OpenCollection(opts CollectionOptions, handler func(*Collection, *Connection)) error {
if cli.ConnectErr == nil {
if con, err := NewConnection(cli.Options); err == nil {
col, colEr := con.Collection(opts)
if colEr != nil {
return newError(Fatal, -1, fmt.Sprintf("Can't open new connection: %v", colEr))
}
handler(col, con)
if er := col.Close(); er != nil {
return er
}
if er := con.Disconnect(); er != nil {
return er
}
return nil
} else {
return newError(Fatal, -1, fmt.Sprintf("Can't open new connection: %v", err))
}
}
return newError(Fatal, -1, fmt.Sprintf("Can't open new connection: %v", cli.ConnectErr))
}
// OpenDataObject will create a new connection using the previously configured iRODS client. It will execute the handler,
// and close *DataObj and *Collection automatically when your handler finishes execution.
// Operations on a single connection are queued when shared between goroutines (iRODS C API
// doesn't support concurrent operations on a single connection), so be sure to open up new connections
// for long-running operations to prevent blocking between goroutines.
func (cli *Client) OpenDataObject(path string, handler func(*DataObj, *Connection)) error {
if cli.ConnectErr == nil {
if con, err := NewConnection(cli.Options); err == nil {
obj, objEr := con.DataObject(path)
if objEr != nil {
return objEr
}
handler(obj, con)
if obj.col != nil {
if er := obj.col.Close(); er != nil {
return er
}
}
if er := con.Disconnect(); er != nil {
return er
}
return nil
} else {
return newError(Fatal, -1, fmt.Sprintf("Can't open new connection: %v", err))
}
}
return newError(Fatal, -1, fmt.Sprintf("Can't open new connection: %v", cli.ConnectErr))
}
// OpenConnection will create a new connection using the previously configured iRODS client. It will execute the handler,
// and close *Collection automatically when your handler finishes execution.
// Operations on a single connection are queued when shared between goroutines (iRODS C API
// doesn't support concurrent operations on a single connection), so be sure to open up new connections
// for long-running operations to prevent blocking between goroutines.
func (cli *Client) OpenConnection(handler func(*Connection)) error {
if cli.ConnectErr == nil {
if con, err := NewConnection(cli.Options); err == nil {
handler(con)
if er := con.Disconnect(); er != nil {
return er
}
return nil
} else {
return newError(Fatal, -1, fmt.Sprintf("Can't open new connection: %v", err))
}
}
return newError(Fatal, -1, fmt.Sprintf("Can't open new connection: %v", cli.ConnectErr))
}
// New creates a test connection to an iRODS iCAT server, and returns a *Client struct if successful.
// EnvironmentDefined and UserDefined constants are used in ConnectionOptions{ Type: ... }).
// When EnvironmentDefined is specified, the options stored in ~/.irods/irods_environment.json will be used.
// When UserDefined is specified you must also pass Host, Port, Username, and Zone. Password
// should be set unless using an anonymous user account with tickets.
func New(opts ConnectionOptions) (*Client, error) {
cli := new(Client)
cli.Options = &opts
if con, err := NewConnection(cli.Options); err != nil {
cli.ConnectErr = err
return nil, err
} else {
if er := con.Disconnect(); er != nil {
return nil, er
}
}
return cli, nil
}
func (cli *Client) DisplayMemInfo() {
C.display_mallinfo()
}