Given that you only add items to the queue and then loop over them once, either map[string]ChargeQueueItem or map[string]*ChargeQueueItem can work. However, using map[string]*ChargeQueueItem might be more efficient in terms of memory allocation, as it allows you to reuse the same ChargeQueueItem struct for each key-value pair in the map, instead of creating a new struct for each pair.
In your current implementation, you are creating a new ChargeQueueItem struct for each key-value pair in the map, which might not be necessary if you are only going to loop over the queue once and then discard it.
By using map[string]*ChargeQueueItem, you can create a slice of pointers to ChargeQueueItem structs, and reuse the same structs for each key-value pair in the map. This can help reduce memory allocation overhead and improve performance, especially if you have a large number of items in the queue.
Here's an example of how you might modify your code to use map[string]*ChargeQueueItem:
type ChargeQueueItem struct {
account string
idUnique string
assetClass string
inverseAssetClass string
chargeDataLicenseCategory string
feeType string
programName string
timestamp string
requestFilename string
replyFilename string
}
// We can key by account+idUnique+chargeDataLicenseCategory
// feetype is not needed as this works across feeTypes
// Timestamp also not as unique charge only happens once per month
var chargeQueue map[string]*ChargeQueueItem = make(map[string]*ChargeQueueItem)
// Create a slice of pointers to ChargeQueueItem structs
var queueItems []*ChargeQueueItem
// Add an item to the queue
newItem := &ChargeQueueItem{
account: "account1",
idUnique: "id1",
assetClass: "class1",
inverseAssetClass: "class2",
chargeDataLicenseCategory: "cat1",
feeType: "type1",
programName: "name1",
timestamp: "time1",
requestFilename: "file1",
replyFilename: "file2",
}
chargeQueue[newItem.key()] = newItem
queueItems = append(queueItems, newItem)
// Loop over the queue
for _, item := range queueItems {
// Process the item
// ...
}
In this example, we create a slice of pointers to ChargeQueueItem structs, and add each new item to the chargeQueue map using its key. We also append each new item to the queueItems slice, so that we can loop over it later.
When processing the queue, we can loop over the queueItems slice and access each item's properties using the pointer. This way, we can reuse the same ChargeQueueItem structs for each key-value pair in the chargeQueue map, without having to create a new struct for each pair.