A robust self-hosted API written in Go, created to centralize file storage/serve.
- Security: JWT Auth.
- Scalability: Rate Limiting.
- Encrypted Local Storage: Encrypted physical files for simple/secure backup/restore.
- Modularity: Clear responsability separation between domains.
- Non Trivial storage Each file stored generates a
storage keywhich decides where the file is located
git clone https://github.com/Angel-del-dev/Filenest-V2.git filenest-v2
cd filenest-v2
go mod download
cp .env-example .env# Database schema can be found in
/schema/db.sql--psql
|> insert into users(email, password, role) values ('...', '...', 'admin');github.com/gofiber/fiber/v3: Go Web framework.github.com/jackc/pgx/v5: PostgreSQL driver.golang.org/x/crypto/bcrypt: Secure hash creation/validation.crypto/aes: Encryptioncrypto/cipher: Encryptioncrypto/hmac: Encryptioncrypto/rand: Encryptioncrypto/sha256: Encryptionncoding/hex: Encryption
cd scripts
./runbuild.sh- Go (Versión 1.20+, preferably 1.25)
- PostgreSQL engine.
Project startup depends on .env variables.
| Var | Description | Type | Required | Domain |
|---|---|---|---|---|
DB_HOST |
Database host. | string |
true |
DB |
DB_NAME |
Database name. | string |
true |
DB |
DB_USER |
Database username. | string |
true |
DB |
DB_PASSWORD |
Database password. | string |
true |
DB |
DB_PORT |
Database port. | int |
true |
DB |
DB_SSLMODE |
Database sslmode. | string |
true |
DB |
JWT_SECRET |
Secret string to authenticate/create tokens(Random). | string |
true |
JWT |
ENCRYPTION_KEY |
Generated for file encryption(Random). | string |
true |
ENCRYPTION |
HMAC_KEY |
Generated for file encryption(Random). | string |
true |
ENCRYPTION |
MAX_REQUESTSPERMINUTE |
Rate limiting. | int |
true |
RATE_LIMIT |
Obtains a JWT token
- Method:
POST - Endpoint:
/auth - Middleware:
ContentTypeAllowed("application/json") - Request body:
{ "user": "<string>", "password": "<string>" } - Response (200 OK): Returns auth token and expiration date
{ "access_token": "<string>", "expires_at": "<string>", "expires_in": "<integer>" } - Errors:
400 Bad Request: Invalid or insufficient parameters.401 Unauthorized: Invalid or credentials.403 Forbidden: User blocked(After 5 consecutive attempts to login with a wrong password).500 Internal Server Error: Serverside error.
Creates a new user.
- Method:
POST - Route:
/users - Middleware: JWT Middleware (
SecretJWT), Content Type JSON, JWT Role is admin. - Request body:
{ "user": "<string>", "password": "<string>" } - Response (200 OK):
{}(Success) - Errors:
400 Bad Request: Invalid request.401 Unauthorized: Expired or invalid JWT Token.409 Conflict: User already exists.500 Internal Server Error: Serverside Error.
Removes a user.
- Method:
DELETE - Route:
/users - Middleware: JWT Middleware (
SecretJWT), Content Type JSON, JWT Role is admin. - Request body:
{ "user": "<string>" } - Response (200 OK):
{}(Success) - Errors:
400 Bad Request: Invalid request.404 Not Found: User not found.500 Internal Server Error: Serverside error.
Locally stores an encrypted file.
- Method:
POST - Route:
/resources - Middleware: JWT Middleware (
SecretJWT), Content Type multipart/form-data, JWT Role is NOT admin. - Request body:
{ "protected": "<string>", // This parameter is optional and must be either 'false', 'true', '0' or '1' "file": "<file>" } - Response (200 OK):
{}(Success) - Errors:
400 Bad Request: Invalid request.401 Unauthorized: Expired or invalid JWT Token.500 Internal Server Error: Serverside Error.
Removes a stored file.
- Method:
DELETE - Route:
/resources/{file_id} - Middleware: JWT Middleware (
SecretJWT), JWT Role is NOT admin. - Response (200 OK):
{}(Success) - Errors:
400 Bad Request: Invalid request.401 Unauthorized: Expired or invalid JWT Token.404 Not found: Resource linked to the user is not found.500 Internal Server Error: Serverside Error.
Serves a stored file.
- Method:
GET - Route:
/resources/{file_id} - Middleware: JWT Middleware(Only if the file was created with
PROTECTED), JWT Role is NOT admin. - Response (200 OK):
<file>(Success) - Errors:
400 Bad Request: Invalid request.401 Unauthorized: Expired or invalid JWT Token.404 Not found: Resource linked to the user is not found.500 Internal Server Error: Serverside Error.