A simple file store application consisting of a backend API and a CLI client. The backend API uses Go's net/http package, and the CLI client is built using cobra. The application allows you to add, retrieve, update, and delete text files, as well as perform word count and frequency analysis across all stored files.
- File Store Application
- Table of Contents
- Features
- Requirements
- Installation
- Usage
- Commands
- Examples
- Docker:
- Kubernetes
- Step 1. Deploy the Configuration to the Kubernetes Cluster
- Step 2. Check for pods in the same namespace using kubectl get pods and make sure the containers in the pod are up& running
- Step 3. Do a kubectl portforward service/file-service be able to access it outside the kind cluster
- Step 4. Verify using curl
- License
- Add Files: Upload one or more text files to the store.
- List Files: Display all filenames currently stored.
- Retrieve File: Get the content of a specific file.
- Update File: Update the content of an existing file or add a new file.
- Delete File: Remove a file from the store.
- Word Count: Get the total word count across all stored files.
- Frequent Words: Display the most or least frequent words across all files.
- Go: Version 1.16 or higher. Download Go
- Cobra: For the CLI application. Install Cobra CLI
- Docker: Required for containerization and running containerized applications. Install Docker
- kubectl: Kubernetes command-line tool for interacting with Kubernetes clusters. Install kubectl
- kind: Tool for running local Kubernetes clusters using Docker container "nodes". Install kind
Note: Ensure that Docker is running before using
kindandkubectl.
- Clone the Repository:
git clone https://github.com/yourusername/filestore.git cd filestore - Install Dependencies: Install cobra for the CLI application:
go get -u github.com/spf13/cobra
- Navigate to the server directory and run the server:
cd cmd/file-server go run main.go - The server will start on port 8080.
- Navigate to the cli directory and build the CLI application:
cd cmd/store-client go build -o store main.go - This will create an executable named store.
-
Add Files
Upload one or more files to the store:./store add file1.txt file2.txt
-
List Files
List all files stored on the server:./store ls
-
Get File Content
Retrieve the content of a specific file:./store get file1.txt
-
Update File
Update the content of an existing file or add a new file:./store update file1.txt
-
Delete File
Remove a file from the store:./store rm file1.txt
-
Word Count
Get the total word count across all stored files:./store wc
-
Frequent Words
Display the most or least frequent words across all files:./store freq-words [--limit|-n NUMBER] [--order=asc|dsc]
- Adding Files
echo "Hello World" > hello.txt echo "Go is awesome" > go.txt ./store add hello.txt go.txt
- Listing Files
./store ls
- Retrieving File Content
./store get hello.txt
- Updating a File
echo "Hello Go" > hello.txt ./store update hello.txt ./store get hello.txt
- Deleting a File
./store rm go.txt ./store ls
- Word Count
./store wc
- Frequent Words
./store freq-words -n 5 --order=dsc
You can also try using the Docker build
docker build . -t fileserverdocker run -p 8081:8080 fileserver:latestOne would see the following logs and can access the server at localhost:8081/files
2024/12/03 06:31:10 Server is running on port 8080...
To deploy on a Kubernetes cluster, we need to do a docker build and push to one's registry. Make sure the image is publicly available. Use kustomize tool and replace your image name accordingly in the kustomize.yaml. These steps are tried on a Kind cluster:
kubectl apply -k kube/configYou would see
service/file-store-service created
deployment.apps/file-store-deployment created
➜ To get the deployments:
kubectl get deploymentsYou would see
NAME READY UP-TO-DATE AVAILABLE AGE
file-store-deployment 1/1 1 1 31s
Step 2. Check for pods in the same namespace using kubectl get pods and make sure the containers in the pod are up& running
kubectl get podsYou would see
NAME READY STATUS RESTARTS AGE
file-store-deployment-7f9dd45957-pj2pd 1/1 Running 0 10s
kubectl port-forward services/file-store-service 8080:8080You would see:
Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080
Handling connection for 8080
Handling connection for 8080
curl http://localhost:8080/files