harbor run -t openthoughts/tasktrove-exp-rpt-stack-go-v4-stack-go-1308harbor download openthoughts/tasktrove-exp-rpt-stack-go-v4-stack-go-1308Implement a CSV handling functionality that allows for reading from and writing to CSV files in a structured manner. The solution should consist of a CSV struct that provides methods for initializing a CSV from a file, appending rows, saving the contents to the file, and retrieving rows based on their index. This functionality must support both default and custom delimiters, handling of large datasets efficiently, and ensure thread-safety during concurrent writes.
Struct Definition:
CSV struct with appropriate fields to manage file metadata, including file path and a delimiter.Methods:
NewCSV with default parameters (comma delimiter, no header).testCsvNode) and appends its data to the CSV file.testCsvNode) to populate with data from the specified row.Thread Safety:
Append method is safe for concurrent access, potentially using synchronization primitives such as mutexes.Performance Considerations:
Testing:
/app/ directory.TestCSVTag, TestCSV_CustomTag, TestCSV_EmptyFile, Benchmark_AppendFile, and Benchmark_Parallel test cases provided in the test code pass successfully, confirming both functionality and performance.Please ensure that the code follows best practices for Go, including error handling and documentation.
Important: declare your solution in package grapeCSV (the test file uses package grapeCSV, so the implementation must use the matching package name).