I'm a Go newbie trying to override some methods in the AWS Go SDK for DynamoDB. Basically, I would like to add some logging to certain methods in the DynamoDB client. The code that I have is:
type dynamoDBLogger struct {
dynamodb.DynamoDB
}
func (d *dynamoDBLogger) DeleteItemWithContext(ctx context.Context, item *dynamodb.DeleteItemInput) (*dynamodb.DeleteItemOutput, error) {
logger.Debug("Deleting from DynamoDB: %+v", *item)
return d.DynamoDB.DeleteItemWithContext(ctx, item)
}
In other words, it just adds a logging statement before the actual call. This code compiles. The problem is now how can I create a dynamoDBLogger? The only way to instantiate a DynamoDB is by using a method:
func New(...) *dynamodb.DynamoDB
in the dynamodb package. Can I somehow use that to build an instance of a dynamoDBLogger? Not sure if it'll work, but I would like for the *dynamoDbLogger type to be usable as a *dynamodb.DynamoDB.
EDIT: I actually noticed that the following fails:
func GetDynamoClient(sess *session.Session) *dynamodb.DynamoDB {
svc := dynamoDBLogger{}
svc.DynamoDB = *dynamodb.New(sess)
return &svc
}
i.e. the type system doesn't allow substituting a *dynamodb.DynamoDB with a *dynamoDBLogger. I'm wondering if Go's type system allows what I'm trying to accomplish, since dynamodb.DynamoDB is not an interface?
*dynamodb.DynamoDBpointer as input. When running the software in debug mode, I would like for all DB queries to get dumped to logs. Without having to modify all the other code, I could just instantiate thedynamodb.DynamoDBpointer in the software config with my own extension. In other words, I just want to add logging statements to some of the methods.