A Go web service that performs various operations on square matrices provided via CSV files.
- Echo: Returns the matrix as a string in matrix format
- Invert: Returns the matrix with columns and rows inverted
- Flatten: Returns the matrix as a single line string
- Sum: Returns the sum of all integers in the matrix
- Multiply: Returns the product of all integers in the matrix
- Go 1.24.4 or higher
- Git
- Clone the repository:
git clone https://github.com/edtk/go-matrix.git
cd go-matrix- Start the server:
go run .- The server will start on port 8080.
You can test the endpoints using curl. Here are examples for each operation:
# Echo - Returns the matrix as is
curl -F 'file=@matrix.csv' "localhost:8080/echo"
# Expected output:
# 1,2,3
# 4,5,6
# 7,8,9
# Invert - Returns the matrix with columns and rows inverted
curl -F 'file=@matrix.csv' "localhost:8080/invert"
# Expected output:
# 1,4,7
# 2,5,8
# 3,6,9
# Flatten - Returns the matrix as a single line
curl -F 'file=@matrix.csv' "localhost:8080/flatten"
# Expected output:
# 1,2,3,4,5,6,7,8,9
# Sum - Returns the sum of all integers
curl -F 'file=@matrix.csv' "localhost:8080/sum"
# Expected output:
# 45
# Multiply - Returns the product of all integers
curl -F 'file=@matrix.csv' "localhost:8080/multiply"
# Expected output:
# 362880The input should be a CSV file containing a square matrix of integers. For example:
1,2,3
4,5,6
7,8,9
Requirements for the input file:
- Must be a square matrix (equal number of rows and columns)
- Must contain only integers
- No header row
- Values separated by commas
- Each row on a new line
The service handles various error cases:
- Invalid CSV format
- Non-square matrices
- Non-integer values
- Empty matrices
- Missing or invalid file uploads
To run the tests:
go test ./matrix