Filebox provides access permission control for files and directories.

You could utilize Filebox to satisfy the following scenarios:

Scenario 1:

  • You would like to make a file, let's say ~/documents/files/users.csv, downloadable via the URL
  • restrict downloads of that file to Admin users.

Scenario 2:

  • Restricting access to files within a folder, let's say ~/exchanges, to Admin users.



import (

func main() {
  mux := http.NewServeMux()

  // Mount filebox into `/downloads`
  Filebox := filebox.New("/home/qor/project/downloads")
  Filebox.MountTo("/downloads", mux)

  // Assert folder downloads has file users.csv
  // then you could download this file by

  // Add permission for users.csv, limit to only admin user able to access
  permission := roles.Allow(roles.Read, "admin")
  userFile := Filebox.AccessFile("users.csv")
  // read content from file `users.csv`
  fileContentReader, err := userFile.Read()
  // write content for file `users.csv`

  // Add permission for a specific directory
  exchangesDir := Dir.AccessDir("/exchanges")
  // Create a new file and it will use directory's permission if it hasn't define its own
  exchangesDir.WriteFile("products.csv", strings.NewReader("Content"))

results matching ""

    No results matching ""