@@ -2,6 +2,7 @@ package client
2
2
3
3
import (
4
4
"bytes"
5
+ "context"
5
6
"crypto/tls"
6
7
"encoding/json"
7
8
"fmt"
@@ -44,11 +45,13 @@ func NewGraphClient(URL, authToken, basicAuthUser, basicAuthPass string, skipVer
44
45
}
45
46
}
46
47
47
- func (gc * GraphClient ) newRequest (method , path string , body io.Reader ) (* http.Request , error ) {
48
+ func (gc * GraphClient ) newRequest (ctx context. Context , method , path string , body io.Reader ) (* http.Request , error ) {
48
49
req , err := http .NewRequest (method , fmt .Sprintf ("%s%s" , gc .url , path ), body )
49
50
if err != nil {
50
51
return nil , err
51
52
}
53
+ req = req .WithContext (ctx )
54
+
52
55
if gc .authToken != "" {
53
56
req .Header .Add (utils .XAuthTokenHeader , gc .authToken )
54
57
}
@@ -60,7 +63,7 @@ func (gc *GraphClient) newRequest(method, path string, body io.Reader) (*http.Re
60
63
61
64
// ReadCurrentGraph read the current graph stored in graph kb
62
65
func (gc * GraphClient ) ReadCurrentGraph () (* knowledge.Graph , error ) {
63
- req , err := gc .newRequest ("GET" , "/api/graph/read" , nil )
66
+ req , err := gc .newRequest (context . Background (), "GET" , "/api/graph/read" , nil )
64
67
if err != nil {
65
68
return nil , err
66
69
}
@@ -96,7 +99,7 @@ func (gc *GraphClient) UpdateSchema(sg schema.SchemaGraph) error {
96
99
return fmt .Errorf ("Unable to marshall request body" )
97
100
}
98
101
99
- req , err := gc .newRequest ("PUT" , "/api/graph/schema" , bytes .NewBuffer (b ))
102
+ req , err := gc .newRequest (context . Background (), "PUT" , "/api/graph/schema" , bytes .NewBuffer (b ))
100
103
if err != nil {
101
104
return err
102
105
}
@@ -127,7 +130,7 @@ func (gc *GraphClient) InsertAssets(assets []knowledge.Asset) error {
127
130
return fmt .Errorf ("Unable to marshall request body" )
128
131
}
129
132
130
- req , err := gc .newRequest ("PUT" , "/api/graph/assets" , bytes .NewBuffer (b ))
133
+ req , err := gc .newRequest (context . Background (), "PUT" , "/api/graph/assets" , bytes .NewBuffer (b ))
131
134
if err != nil {
132
135
return err
133
136
}
@@ -158,7 +161,7 @@ func (gc *GraphClient) DeleteAssets(assets []knowledge.Asset) error {
158
161
return fmt .Errorf ("Unable to marshall request body" )
159
162
}
160
163
161
- req , err := gc .newRequest ("DELETE" , "/api/graph/assets" , bytes .NewBuffer (b ))
164
+ req , err := gc .newRequest (context . Background (), "DELETE" , "/api/graph/assets" , bytes .NewBuffer (b ))
162
165
if err != nil {
163
166
return err
164
167
}
@@ -189,7 +192,7 @@ func (gc *GraphClient) InsertRelations(relations []knowledge.Relation) error {
189
192
return fmt .Errorf ("Unable to marshall request body" )
190
193
}
191
194
192
- req , err := gc .newRequest ("PUT" , "/api/graph/relations" , bytes .NewBuffer (b ))
195
+ req , err := gc .newRequest (context . Background (), "PUT" , "/api/graph/relations" , bytes .NewBuffer (b ))
193
196
if err != nil {
194
197
return err
195
198
}
@@ -220,7 +223,7 @@ func (gc *GraphClient) DeleteRelations(relations []knowledge.Relation) error {
220
223
return fmt .Errorf ("Unable to marshall request body" )
221
224
}
222
225
223
- req , err := gc .newRequest ("DELETE" , "/api/graph/relations" , bytes .NewBuffer (b ))
226
+ req , err := gc .newRequest (context . Background (), "DELETE" , "/api/graph/relations" , bytes .NewBuffer (b ))
224
227
if err != nil {
225
228
return err
226
229
}
0 commit comments