This Golang application demonstrates how to list files stored in a Google Cloud Storage (GCS) bucket with pagination support. The application uses Google Cloud Storage API to retrieve file information and returns the results in a JSON format with next and previous page URLs.
-
Go 1.14 or higher installed.
-
A Google Cloud Platform (GCP) project with a GCS bucket containing files.
-
A GCP service account key in JSON format (e.g.,
gcp_credential.json
).
The GCPBucket
struct represents the GCS bucket configuration, including the bucket name and the JSON credential file.
The FileInfo
struct represents the metadata of a file in the GCS bucket, such as the file name, creation time, content type, and media URL.
The FileListResponse
struct represents the JSON response format, including the limit, next and previous page URLs, current page number, file information, and total number of files returned.
- Clone this repository and navigate to the project directory:
git clone https://github.com/AIbnuHIbban/list-files-gcs-pagination.git
cd list-files-gcs-pagination
-
Replace the
bucketInfo
inmain.go
with your GCS bucket information and thegcp_credential.json
file with your GCP service account key. -
Run the application:
go run main.go
- Access the
/list
endpoint with your browser or a tool likecurl
or Postman, using the appropriate query parameters, for example:
http://localhost:8080/list?page=1&limit=10
The response will be in JSON format, with the file information and pagination URLs.