goflet

command module
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2024 License: MIT Imports: 5 Imported by: 0

README ยถ

goflet

Goflet


Goflet is a lightweight file upload and download service written in Go.

license codacy-quality go-report

๐Ÿค” What is Goflet?

Goflet implements a lightweight file upload and download service. It is a web service based on the Go language and uses the Gin framework. Although Goflet has simple functions, it supports features such as breakpoint resumption during upload and download, and multi-threaded downloading. Goflet's file download interface follows various HTTP standards, so if your service needs are relatively simple, Goflet can fully serve as your CDN service. In addition to file upload and download, Goflet also provides simple image processing, OnlyOffice synchronization, and other functions.

๐Ÿš€ Features

  • Lightweight: Only one binary file is needed to run Goflet.
  • Easy to use: Goflet's API interface follows HTTP standards, so you can easily use it.
  • Breakpoint resumption: Supports breakpoint resumption during upload and download, improving the stability and efficiency of file transmission.
  • Multi-threaded download: Supports multi-threaded downloading to speed up the file download process.
  • Image processing: Provides simple image processing functions, such as image compression, scaling, etc.
  • OnlyOffice synchronization: Supports synchronization editing of OnlyOffice documents.
  • JWT authentication: Supports JWT authentication to ensure the security of your files.
  • Docker support: Supports Docker deployment for convenience and speed.
  • Cross-platform: Goflet supports operating systems such as Windows, Linux, macOS, etc.

๐Ÿ“ฆ Installation and Deployment

Docker / Docker Compose

Some example Docker Compose files are already prepared in the docker directory. You can directly use them to deploy Goflet.

git clone https://github.com/vvbbnn00/goflet.git
cd goflet
docker-compose up -d

Binary File

You can download the binary file of Goflet from the Releases page and then run it on your server.

Source Code Compilation

You can also install Goflet through source code compilation. First, you need to install the Go language runtime environment, and then execute the following commands:

git clone https://github.com/vvbbnn00/goflet.git
cd goflet
go build -o goflet

๐Ÿ“„ Configuration File

Warning

Please be sure to modify the JWT signature key in goflet.json before deploying Goflet.

The configuration file of Goflet is goflet.json. When Goflet is run for the first time, it will be automatically generated. You can configure various parameters of Goflet in goflet.json, such as the listening port, file storage path, etc. After you have finished modifying the configuration, you need to restart Goflet for the configuration to take effect.

Below is a detailed explanation of the goflet.json configuration file:

{
  // Whether to enable debug mode
  "debug": false,
  // Log configuration
  "logConfig": {
    // Whether to enable logging
    "enabled": true,
    // Log level (debug, info, warn, error, fatal)
    "level": "info"
  },
  // Whether to enable Swagger documentation
  "swaggerEnabled": true,
  // HTTP service configuration
  "httpConfig": {
    // Listening address
    "host": "0.0.0.0",
    // Listening port
    "port": 8080,
    // Whether to enable CORS
    "cors": {
      "enabled": true,
      // Allowed origins
      "origins": [
        "*"
      ],
      // Allowed methods
      "methods": [
        "HEAD",
        "GET",
        "POST",
        "PUT",
        "DELETE",
        "OPTIONS"
      ],
      // Allowed headers
      "headers": [
        "Content-Type",
        "Authorization"
      ]
    },
    // Browser cache configuration
    "clientCache": {
      // Whether to enable browser caching
      "enabled": true,
      // Cache time
      "maxAge": 3600
    },
    // HTTPS configuration
    "httpsConfig": {
      "enabled": false,
      // Certificate path
      "cert": "cert/cert.pem",
      // Private key path
      "key": "cert/key.pem"
    }
  },
  // File storage configuration
  "fileConfig": {
    // File storage path
    "baseFileStoragePath": "data",
    // Whether to allow folder creation
    "allowFolderCreation": true,
    // Whether to allow file upload
    "uploadPath": "upload",
    // Upload file size limit
    "uploadLimit": 1073741824,
    // Upload timeout
    "uploadTimeout": 7200
  },
  // Cache configuration
  "cacheConfig": {
    // Cache type (Cache, ...)
    "cacheType": "Cache",
    // In-memory cache configuration
    "Cache": {
      // Maximum number of cache entries
      "maxEntries": 1000,
      // Default TTL
      "defaultTTL": 60
    }
  },
  // Image processing configuration
  "imageConfig": {
    // Default format (jpeg, png, gif)
    "defaultFormat": "jpeg",
    // Allowed formats (png, jpeg, gif)
    "allowedFormats": [
      "png",
      "jpeg",
      "gif"
    ],
    // Strict mode, if enabled, only allowed sizes are permitted
    "strictMode": true,
    // Allowed sizes
    "allowedSizes": [
      16,
      32,
      64,
      128,
      256,
      512,
      1024
    ],
    // Maximum file size
    "maxFileSize": 20971520,
    // Maximum width
    "maxWidth": 4096,
    // Maximum height
    "maxHeight": 4096
  },
  // JWT configuration
  "jwtConfig": {
    // Whether to enable JWT (strongly recommended if you are deploying on the public network)
    "enabled": true,
    // JWT algorithm, supports HS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384, ES512
    "algorithm": "HS256",
    // JWT security configuration
    "Security": {
      // JWT signing key, please be sure to modify it when deploying
      "signingKey": "goflet",
      // PKCS8 format public key
      "publicKey": "",
      // PKCS8 format private key (since this project does not actively distribute JWT at present, it can be left empty)
      "privateKey": ""
    },
    // Trusted issuers, if empty, will not be verified
    "trustedIssuers": null
  },
  // Automatic task configuration (if 0, then not enabled, in seconds)
  "cronConfig": {
    // Delete empty folders
    "deleteEmptyFolder": 3600,
    // Clean outdated upload files
    "cleanOutdatedFile": 3600
  }
}

๐Ÿ“ API Documentation

The integrated Swagger documentation can be accessed at http://<host>:<port>/swagger/index.html. You can use it to easily understand and use Goflet's API.

If you want to disable the Swagger documentation, you can set swaggerEnabled to false in goflet.json.

Authentication Method

Goflet's authentication method is JWT. You can configure the JWT-related parameters in goflet.json. If you are deploying on the public network, it is strongly recommended that you enable JWT.

JWT Format Explanation

Here is an example of a JWT. You can use JWT.io to parse it. It uses the HS256 algorithm, and the signing key is goflet

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnb2ZsZXQiLCJpYXQiOjE3MTAwMDgxNTk
sImV4cCI6MTcxMDA5NDU1OSwibmJmIjoxNzEwMDA4MTU5LCJwZXJtaXNzaW9ucyI6W3sicGF0aCI6Ii9
hcGkvaW1hZ2UvdGVzdC93YWxscGFwZXIucG5nIiwibWV0aG9kcyI6WyJHRVQiXSwicXVlcnkiOnsiaCI
6IjY0IiwidyI6IjY0IiwiZiI6ImpwZWcifX0seyJwYXRoIjoiL2ZpbGUvaW1hZ2VzLyoiLCJtZXRob2R
zIjpbIkdFVCJdfV19.DYSxViy895kjycdt3k0MRNV9UCPho4QsAlRbZ4D9Kik

Payload:

{
  "iss": "goflet",
  "iat": 1710008159,
  "exp": 1710094559,
  "nbf": 1710008159,
  // Permission list, here you can configure the permissions of this JWT, multiple permissions can be configured
  "permissions": [
    {
      // Allowed path, excluding domain and port, supports wildcard (paths after the wildcard will not be verified)
      "path": "/api/image/test/wallpaper.png",
      // Allowed methods (GET, POST, PUT, DELETE, HEAD)
      "methods": [
        "GET"
      ],
      // Allowed parameters, if empty, will not be verified, the parameters configured here need to be exactly matched in the request, other parameters will not be verified, wildcards are not supported
      "query": {
        "h": "64",
        "w": "64",
        "f": "jpeg"
      }
    },
    // query is not mandatory, you can also not set parameters, this will allow all requests
    {
      "path": "/file/images/*",
      // However, you need to set methods, otherwise, it will not be verified
      "methods": [
        "GET"
      ]
    }
  ]
}

๐Ÿ“œ License

Goflet is licensed under the MIT License. See the LICENSE file for details.

Documentation ยถ

Overview ยถ

Package main provides the entry point for the application

Directories ยถ

Path Synopsis
Package base provides the base information for the application
Package base provides the base information for the application
Package cache provides the cache for the application
Package cache provides the cache for the application
memory
Package memory provides the memory cache for the application
Package memory provides the memory cache for the application
model
Package model provides the model for the cache
Package model provides the model for the cache
Package config provides the configuration for the application
Package config provides the configuration for the application
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
Package middleware provides the middleware for the application
Package middleware provides the middleware for the application
Package route provides the routes for the application
Package route provides the routes for the application
api
Package api provides the routes for the API
Package api provides the routes for the API
api/action
Package action provides the routes for the action API
Package action provides the routes for the action API
api/image
Package image provides the routes for the image API
Package image provides the routes for the image API
api/meta
Package meta provides the routes for the meta API
Package meta provides the routes for the meta API
api/onlyoffice
Package onlyoffice provides the routes for the OnlyOffice API
Package onlyoffice provides the routes for the OnlyOffice API
file
Package file provides the routes for the file package
Package file provides the routes for the file package
Package storage provides functions to interact with the file storage
Package storage provides functions to interact with the file storage
hasher
Package hasher provides a simple interface to hash files and update the hash of the file in the database.
Package hasher provides a simple interface to hash files and update the hash of the file in the database.
image
Package image provides image processing functions for the application.
Package image provides image processing functions for the application.
model
Package model provides the data models for the application.
Package model provides the data models for the application.
upload
Package upload provides functions for uploading files to the server
Package upload provides functions for uploading files to the server
Package task provides functions for running scheduled tasks
Package task provides functions for running scheduled tasks
Package util provides utility functions for the application
Package util provides utility functions for the application
base58
Package base58 provides base58 encoding and decoding functions.
Package base58 provides base58 encoding and decoding functions.
confutil
Package confutil provides the utility functions for the configuration
Package confutil provides the utility functions for the configuration
hash
Package hash provides a simple interface to hash strings and files using various algorithms.
Package hash provides a simple interface to hash strings and files using various algorithms.
log
Package log provides a simple logging utility for the application.
Package log provides a simple logging utility for the application.
Package winres generates winres.json
Package winres generates winres.json
json
Package main generates winres.json, modified from: https://github.com/Mrs4s/go-cqhttp/blob/master/winres/gen/json.go
Package main generates winres.json, modified from: https://github.com/Mrs4s/go-cqhttp/blob/master/winres/gen/json.go
Package worker provides a pool of workers to execute jobs
Package worker provides a pool of workers to execute jobs

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL