Skip to content
qorPublic

About

Filebox could be used to provide access permission control for files, directories

Resources

Stars

9 stars

Watchers

11 watching

Forks

Latest commit

 

History

35 Commits

Folders and files

Repository files navigation

Filebox

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 http://127.0.0.1/downloads/users.csv.
  • restrict downloads of that file to Admin users.

Scenario 2:

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

GoDoc

Usage

import (
  "github.com/qor/filebox"
  "github.com/qor/roles"
  "net/http"
  "string"
)

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 http://127.0.0.1:7000/downloads/users.csv

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

  // Add permission for a specific directory
  exchangesDir := Dir.AccessDir("/exchanges")
  exchangesDir.SetPermission(permission)
  // 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"))
}

License

Released under the MIT License.

About

Filebox could be used to provide access permission control for files, directories

Resources

Stars

9 stars

Watchers

11 watching

Forks

Releases

Packages

Used by

Contributors

Languages

⌂ 换网址