It is a hobby project for me to toy around with go and build some CI/CD Pipelines for go projects.
This ships "as-is", there will be no support, use at own risk, etc.
This Go project implements a simple file server with authentication, rate limiting, and daemon mode support.
- Authentication: Users can authenticate using basic authentication with a username and password.
- Rate Limiting: Requests are rate-limited to prevent abuse.
- Daemon Mode: Supports running as a daemon process.
- HTTPS Support: The server runs over HTTPS with self-signed certificates.
- File Upload/Download: Users can upload and download files securely.
The server can be configured via a JSON configuration file located at ./config/config.json
. You can modify the configuration according to your requirements.
If you're not providing a config a default config will be created:
{
"rateLimit": {
"requestsPerSecond": 1,
"burst": 5
},
"daemon": {
"pidFile": "./config/pid",
"logFile": "./config/log"
},
"port": 8080,
"userFile": "./config/users.json",
"storage": "./data",
"certFolder": "./config/certs"
}
You can also use Docker Compose to manage your file server container. Here's an example docker-compose.yml
file:
version: '3'
services:
go-sfs:
image: mietzen/go-sfs
container_name: go-sfs
ports:
- "8080:8080"
volumes:
- ./config:/config
- ./data:/data
environment:
# - USER_FILE=/config/users.json
# - STORAGE=/data
# - CERTS=/config/certs
- LIMITER_REQUESTS_PER_SECOND=1
- LIMITER_BURST=5
- PORT=8080
Save this file as docker-compose.yml
in your project directory, then run the following command:
docker-compose up -d
This will start the file server container in detached mode, using the configuration specified in the docker-compose.yml
file.
Now you can access your file server at http://localhost:8080
.
You can also override the configuration values using environment variables in the docker-compose.yml
file as shown above.
To add a new user, use the -u
flag followed by the username, and optionally the -p
flag followed by the password:
docker exec go-sfs /go-sfs -u username
To build the Docker image for the file server, navigate to the directory containing your Dockerfile and execute the following command:
docker build -t go-sfs .
You can Download the latest Binary here:
https://github.com/mietzen/go-sfs/releases/latest
or build it yourself.
-
Clone this repository:
git clone https://github.com/mietzen/go-sfs.git
-
Navigate to the project directory:
cd project-directory
-
Build the project:
go build
-
Test the project:
go test
To run the server, execute the built executable:
./go-sfs
You can use the following environment variables to overwrite settings:
- USER_FILE=/config/users.json
- STORAGE=/data
- CERTS=/config/certs
- LIMITER_REQUESTS_PER_SECOND=1
- LIMITER_BURST=5
- PORT=8080
To add a new user, use the -u
flag followed by the username, and optionally the -p
flag followed by the password:
./go-sfs -u username -p password
To run the server in daemon mode, use the -d
flag:
./go-sfs -d
- Upload File:
PUT /upload/{path}
- Upload a file to the specified path.
- Download File:
GET /download/{path}
- Download a file from the specified path.
- List Files:
GET /files
- List all files available for download.
- Delete File:
DELETE /delete/{path}
- Delete a file from the specified path.
curl -u username:password -X PUT -T "path/to/local/file" http://localhost:8080/upload/path/to/remote/file
curl -u username:password -OJ http://localhost:8080/download/path/to/file
curl -u username:password http://localhost:8080/files
curl -u username:password -X DELETE http://localhost:8080/delete/path/to/file
Replace username
, password
, path/to/local/file
, and path/to/remote/file
with appropriate values.
Contributions are welcome! Please feel free to submit issues or pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.