Update docs
Former-commit-id: 70685b598a006623f25a6774fe6084f57cfbe1bf [formerly ccbb5f53ed5d72472604c68e47aa07761c0206f7] [formerly 0b34f9e46762e5b6d940f66f6f1d3a1855d56915 [formerly 154bfb19d5cd4319d4f61ef123ea74510b23ffc7]] Former-commit-id: 9b20eb1064d9ca96d5100c3ea77b52e8675a393d [formerly 3ae727e5bc065815b79a9df4ccbe4b39b0a6a4e4] Former-commit-id: 7e5bd07d8310d5df84a0490c7cb75c94e5fa3026
This commit is contained in:
		
							parent
							
								
									9186c1f36c
								
							
						
					
					
						commit
						269ec9ea4b
					
				| 
						 | 
					@ -0,0 +1,73 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					Package filemanager provides a web interface to access your files
 | 
				
			||||||
 | 
					wherever you are. To use this package as a middleware for your app,
 | 
				
			||||||
 | 
					you'll need to import both File Manager and File Manager HTTP packages.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						import (
 | 
				
			||||||
 | 
							fm "github.com/hacdias/filemanager"
 | 
				
			||||||
 | 
							h "github.com/hacdias/filemanager/http"
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Then, you should create a new FileManager object with your options. In this
 | 
				
			||||||
 | 
					case, I'm using BoltDB (via Storm package) as a Store. So, you'll also need
 | 
				
			||||||
 | 
					to import "github.com/hacdias/filemanager/bolt".
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						db, _ := storm.Open("bolt.db")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						m := &fm.FileManager{
 | 
				
			||||||
 | 
							NoAuth: false,
 | 
				
			||||||
 | 
							DefaultUser: &fm.User{
 | 
				
			||||||
 | 
								AllowCommands: true,
 | 
				
			||||||
 | 
								AllowEdit:     true,
 | 
				
			||||||
 | 
								AllowNew:      true,
 | 
				
			||||||
 | 
								AllowPublish:  true,
 | 
				
			||||||
 | 
								Commands:      []string{"git"},
 | 
				
			||||||
 | 
								Rules:         []*fm.Rule{},
 | 
				
			||||||
 | 
								Locale:        "en",
 | 
				
			||||||
 | 
								CSS:           "",
 | 
				
			||||||
 | 
								Scope:         ".",
 | 
				
			||||||
 | 
								FileSystem:    fileutils.Dir("."),
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							Store: &fm.Store{
 | 
				
			||||||
 | 
								Config: bolt.ConfigStore{DB: db},
 | 
				
			||||||
 | 
								Users:  bolt.UsersStore{DB: db},
 | 
				
			||||||
 | 
								Share:  bolt.ShareStore{DB: db},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							NewFS: func(scope string) fm.FileSystem {
 | 
				
			||||||
 | 
								return fileutils.Dir(scope)
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The credentials for the first user are always 'admin' for both the user and
 | 
				
			||||||
 | 
					the password, and they can be changed later through the settings. The first
 | 
				
			||||||
 | 
					user is always an Admin and has all of the permissions set to 'true'.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Then, you should set the Prefix URL and the Base URL, using the following
 | 
				
			||||||
 | 
					functions:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							m.SetBaseURL("/")
 | 
				
			||||||
 | 
							m.SetPrefixURL("/")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The Prefix URL is a part of the path that is already stripped from the
 | 
				
			||||||
 | 
					r.URL.Path variable before the request arrives to File Manager's handler.
 | 
				
			||||||
 | 
					This is a function that will rarely be used. You can see one example on Caddy
 | 
				
			||||||
 | 
					filemanager plugin.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					The Base URL is the URL path where you want File Manager to be available in. If
 | 
				
			||||||
 | 
					you want to be available at the root path, you should call:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							m.SetBaseURL("/")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					But if you want to access it at '/admin', you would call:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							m.SetBaseURL("/admin")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Now, that you already have a File Manager instance created, you just need to
 | 
				
			||||||
 | 
					add it to your handlers using m.ServeHTTP which is compatible to http.Handler.
 | 
				
			||||||
 | 
					We also have a m.ServeWithErrorsHTTP that returns the status code and an error.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					One simple implementation for this, at port 80, in the root of the domain, would be:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							http.ListenAndServe(":80", h.Handler(m))
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					package filemanager
 | 
				
			||||||
| 
						 | 
					@ -1,56 +1,3 @@
 | 
				
			||||||
// Package filemanager provides a web interface to access your files
 | 
					 | 
				
			||||||
// wherever you are. To use this package as a middleware for your app,
 | 
					 | 
				
			||||||
// you'll need to create a filemanager instance:
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// 		m, err := filemanager.New(database, user)
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// Where 'user' contains the default options for new users. You can just
 | 
					 | 
				
			||||||
// use 'filemanager.DefaultUser' or create yourself a default user:
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// 		m, err := filemanager.New(database, filemanager.User{
 | 
					 | 
				
			||||||
// 			Admin: 		   false,
 | 
					 | 
				
			||||||
// 			AllowCommands: false,
 | 
					 | 
				
			||||||
// 			AllowEdit:     true,
 | 
					 | 
				
			||||||
// 			AllowNew:      true,
 | 
					 | 
				
			||||||
// 			Commands:      []string{
 | 
					 | 
				
			||||||
// 				"git",
 | 
					 | 
				
			||||||
// 			},
 | 
					 | 
				
			||||||
// 			Rules:         []*filemanager.Rule{},
 | 
					 | 
				
			||||||
// 			CSS:           "",
 | 
					 | 
				
			||||||
// 			FileSystem:    webdav.Dir("/path/to/files"),
 | 
					 | 
				
			||||||
// 		})
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// The credentials for the first user are always 'admin' for both the user and
 | 
					 | 
				
			||||||
// the password, and they can be changed later through the settings. The first
 | 
					 | 
				
			||||||
// user is always an Admin and has all of the permissions set to 'true'.
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// Then, you should set the Prefix URL and the Base URL, using the following
 | 
					 | 
				
			||||||
// functions:
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// 		m.SetBaseURL("/")
 | 
					 | 
				
			||||||
// 		m.SetPrefixURL("/")
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// The Prefix URL is a part of the path that is already stripped from the
 | 
					 | 
				
			||||||
// r.URL.Path variable before the request arrives to File Manager's handler.
 | 
					 | 
				
			||||||
// This is a function that will rarely be used. You can see one example on Caddy
 | 
					 | 
				
			||||||
// filemanager plugin.
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// The Base URL is the URL path where you want File Manager to be available in. If
 | 
					 | 
				
			||||||
// you want to be available at the root path, you should call:
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// 		m.SetBaseURL("/")
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// But if you want to access it at '/admin', you would call:
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// 		m.SetBaseURL("/admin")
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// Now, that you already have a File Manager instance created, you just need to
 | 
					 | 
				
			||||||
// add it to your handlers using m.ServeHTTP which is compatible to http.Handler.
 | 
					 | 
				
			||||||
// We also have a m.ServeWithErrorsHTTP that returns the status code and an error.
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// One simple implementation for this, at port 80, in the root of the domain, would be:
 | 
					 | 
				
			||||||
//
 | 
					 | 
				
			||||||
// 		http.ListenAndServe(":80", m)
 | 
					 | 
				
			||||||
package filemanager
 | 
					package filemanager
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue