-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.go
128 lines (114 loc) · 4.56 KB
/
types.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
package gremgoser
import (
"errors"
"sync"
"time"
"github.com/google/uuid"
"github.com/gorilla/websocket"
"github.com/intwinelabs/logger"
)
var (
ErrorInterfaceHasNoIdField = errors.New("gremgoser: the passed interface must have an Id field")
ErrorNoGraphTags = errors.New("gremgoser: the passed interface has no graph tags")
ErrorUnsupportedPropertyMap = errors.New("gremgoser: unsupported property map")
ErrorCannotCastProperty = errors.New("gremgoser: passed property cannot be cast")
ErrorWSConnection = errors.New("gremgoser: error connecting to websocket")
ErrorWSConnectionNil = errors.New("gremgoser: error websocket connection nil")
ErrorConnectionDisposed = errors.New("gremgoser: you cannot write on a disposed connection")
ErrorInvalidURI = errors.New("gremgoser: invalid uri supplied in config")
ErrorNoAuth = errors.New("gremgoser: client does not have a secure dialer for authentication with the server")
Error401Unauthorized = errors.New("gremgoser: UNAUTHORIZED")
Error407Authenticate = errors.New("gremgoser: AUTHENTICATE")
Error498MalformedRequest = errors.New("gremgoser: MALFORMED REQUEST")
Error499InvalidRequestArguments = errors.New("gremgoser: INVALID REQUEST ARGUMENTS")
Error500ServerError = errors.New("gremgoser: SERVER ERROR")
Error597ScriptEvaluationError = errors.New("gremgoser: SCRIPT EVALUATION ERROR")
Error598ServerTimeout = errors.New("gremgoser: SERVER TIMEOUT")
Error599ServerSerializationError = errors.New("gremgoser: SERVER SERIALIZATION ERROR")
ErrorUnknownCode = errors.New("gremgoser: UNKNOWN ERROR")
)
// ClientConfig configs a client
type ClientConfig struct {
URI string
AuthReq *GremlinRequest
Debug bool
Verbose bool
VeryVerbose bool
Timeout time.Duration
PingInterval time.Duration
WritingWait time.Duration
ReadingWait time.Duration
Logger *logger.Logger
}
// Client is a container for the gremgoser client.
type Client struct {
conf *ClientConfig
conn dialer
requests chan []byte
responses chan []byte
errs chan error
results *sync.Map
responseNotifier *sync.Map // responseNotifier notifies the requester that a response has arrived for the request
respMutex *sync.Mutex
Errored bool
}
// Ws is the dialer for a WebSocket connection
type Ws struct {
uri string
conn *websocket.Conn
disposed bool
connected bool
debug bool
verbose bool
pingInterval time.Duration
writingWait time.Duration
readingWait time.Duration
timeout time.Duration
quit chan struct{}
sync.RWMutex
logger *logger.Logger
}
// GremlinRequest is a container for all evaluation request parameters to be sent to the Gremlin Server.
type GremlinRequest struct {
RequestId uuid.UUID `json:"requestId,string"`
Op string `json:"op"`
Processor string `json:"processor"`
Args map[string]interface{} `json:"args"`
}
type GremlinResponse struct {
RequestId uuid.UUID `json:"requestId,string"`
Status GremlinStatus `json:"status"`
Result GremlinResult `json:"result"`
}
type GremlinStatus struct {
Code int `json:"code"`
Attributes GremlinStatusAttributes `json:"attributes"`
Message string `json:"message"`
}
type GremlinStatusAttributes struct {
XMsStatusCode int `json:"x-ms-status-code"`
XMsRequestCharge float32 `json:"x-ms-request-charge"`
XMsTotalRequestCharge float32 `json:"x-ms-total-request-charge"`
XMsServerTimeMs float32 `json:"x-ms-server-time-ms"`
XMsTotalServerTimeMs float32 `json:"x-ms-total-server-time-ms"`
XMsActivityId uuid.UUID `json:"x-ms-activity-id"`
}
type GremlinResult struct {
Data []*GremlinRespData `json:"data"`
Meta interface{} `json:"meta"`
}
type GremlinRespData map[string]interface{}
type GremlinData struct {
Id uuid.UUID `json:"id"`
Label string `json:"label"`
Type string `json:"type"`
InVLabel string `json:"inVLabel"`
OutVLabel string `json:"outVLabel"`
InV uuid.UUID `json"inV"`
OutV uuid.UUID `json"outV"`
Properties map[string]interface{} `json:"properties"`
}
type GremlinProperty struct {
Id uuid.UUID `json:"id"`
Value interface{} `json:"value"`
}