divijvaidya commented on a change in pull request #1556: URL: https://github.com/apache/tinkerpop/pull/1556#discussion_r804094327
########## File path: gremlin-go/driver/client.go ########## @@ -0,0 +1,87 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +package gremlingo + +import ( + "golang.org/x/text/language" +) + +// ClientSettings is used to modify a Client's settings on initialization. +type ClientSettings struct { + TransporterType TransporterType + LogVerbosity LogVerbosity + Logger Logger + Language language.Tag +} + +// Client is used to connect and interact with a Gremlin-supported server. +type Client struct { + host string + port int + logHandler *logHandler + transporterType TransporterType + connection *connection +} + +// NewClient creates a Client and configures it with the given parameters. +func NewClient(host string, port int, configurations ...func(settings *ClientSettings)) *Client { + settings := &ClientSettings{ + TransporterType: Gorilla, + LogVerbosity: Info, + Logger: &defaultLogger{}, + Language: language.English, + } + for _, configuration := range configurations { + configuration(settings) + } + + logHandler := newLogHandler(settings.Logger, settings.LogVerbosity, settings.Language) + client := &Client{ + host: host, + port: port, + logHandler: logHandler, + transporterType: settings.TransporterType, + connection: nil, + } + return client +} + +// Close closes the client via connection +func (client *Client) Close() error { + return client.connection.close() +} + +// Submit submits a Gremlin script to the server and returns a ResultSet +func (client *Client) Submit(traversalString string) (ResultSet, error) { Review comment: please validate input string here and add debug logs to print the start of submit ########## File path: gremlin-go/driver/client.go ########## @@ -0,0 +1,87 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +package gremlingo + +import ( + "golang.org/x/text/language" +) + +// ClientSettings is used to modify a Client's settings on initialization. +type ClientSettings struct { + TransporterType TransporterType + LogVerbosity LogVerbosity + Logger Logger + Language language.Tag +} + +// Client is used to connect and interact with a Gremlin-supported server. +type Client struct { + host string + port int + logHandler *logHandler + transporterType TransporterType + connection *connection +} + +// NewClient creates a Client and configures it with the given parameters. +func NewClient(host string, port int, configurations ...func(settings *ClientSettings)) *Client { + settings := &ClientSettings{ + TransporterType: Gorilla, + LogVerbosity: Info, + Logger: &defaultLogger{}, + Language: language.English, + } + for _, configuration := range configurations { + configuration(settings) + } + + logHandler := newLogHandler(settings.Logger, settings.LogVerbosity, settings.Language) + client := &Client{ + host: host, + port: port, + logHandler: logHandler, + transporterType: settings.TransporterType, + connection: nil, + } + return client +} + +// Close closes the client via connection +func (client *Client) Close() error { + return client.connection.close() +} + +// Submit submits a Gremlin script to the server and returns a ResultSet Review comment: please specify in documentation that this is synchronous/blocking call ########## File path: gremlin-go/driver/gorillaTransporter.go ########## @@ -0,0 +1,91 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +package gremlingo + +import ( + "net/url" + "strconv" + + "github.com/gorilla/websocket" +) + Review comment: documentation ########## File path: gremlin-go/driver/transporterFactory.go ########## @@ -0,0 +1,37 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +package gremlingo + +// TransporterType is an alias for valid transport protocols. +type TransporterType int + +const ( + // Gorilla transport layer: github.com/gorilla/websocket + Gorilla TransporterType = iota Review comment: as a general style guide, let us start enums from 1 because variables have a 0 default value and hence starting an enum from 1 will help distinguish between uninitialized enum vs. intentional value of an enum ########## File path: gremlin-go/driver/request.go ########## @@ -0,0 +1,42 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +package gremlingo + +import "github.com/google/uuid" + +const op = "eval" +const processor = "" + +// request represents a request to the server +type request struct { + requestID uuid.UUID `json:"requestId"` + op string `json:"op"` + processor string `json:"processor"` + args map[string]interface{} `json:"args"` +} + +func makeStringRequest(requestString string) (req request) { + return request{uuid.New(), op, processor, map[string]interface{}{ + "gremlin": requestString, + "aliases": map[string]interface{}{ + "g": "g", Review comment: please add a TODO to make this configurable in future (similar to AliasedClient in Java). ########## File path: gremlin-go/driver/gorillaTransporter.go ########## @@ -0,0 +1,91 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +package gremlingo + +import ( + "net/url" + "strconv" + + "github.com/gorilla/websocket" +) + +type gorillaTransporter struct { + host string + port int + connection websocketConn + isClosed bool +} + +func (transporter *gorillaTransporter) Connect() (err error) { + if transporter.connection != nil { + return Review comment: please return an error so that caller can know it is a non-retriable error and also that it is a configuration error. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
