abenn135 commented on code in PR #1943: URL: https://github.com/apache/cassandra-gocql-driver/pull/1943#discussion_r3243674977
########## example_interceptor_test.go: ########## @@ -0,0 +1,138 @@ +/* + * 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. + */ +/* + * Content before git sha 34fdeebefcbf183ed7f916f931aa0586fdaa1b40 + * Copyright (c) 2016, The Gocql authors, + * provided under the BSD-3-Clause License. + * See the NOTICE file distributed with this work for additional information. + */ + +package gocql_test + +import ( + "context" + "log" + "time" + + gocql "github.com/apache/cassandra-gocql-driver/v2" +) + +type MyQueryAttemptInterceptor struct { + injectFault bool +} + +func (q MyQueryAttemptInterceptor) Intercept( + ctx context.Context, + attempt gocql.QueryAttempt, + handler gocql.QueryAttemptHandler, +) (*gocql.Iter, error) { + switch q := attempt.Statement.Statement().(type) { + case *gocql.Query: + // Inspect query + log.Println(q.Statement()) + case *gocql.Batch: + // Inspect batch + + log.Println(q.Entries[0].Stmt) + } Review Comment: I think I have an idea of how you could do this... 1. Add read-only QueryView/BatchView interfaces that only offer the getters on Query/Batch. 2. Move all members on Query and Batch to new privateQuery/privateBatch structs. These structs offer the public getters and therefore implement QueryView/BatchView APIs, but have package-private setters. 3. Update Query and Batch to just hold a ref to an underlying privateQuery/privateBatch, and have their public getters and setters proxy to the public getters and package-private setters on their private* members. 4. At Exec/Intercept time, you offer only the privateQuery/privateBatch, which implement the QueryView/BatchView public getters, but do not implement the setters on the Query/Batch interfaces. This seems like it would work to provide an immutable view of the Query/Batch without a deep copy. We'd also need an affordance to set the trace, which might be done through a specific callback func or something. Let me know what you think of this. I could do it in a separate PR if you prefer. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

