Documentation ¶
Overview ¶
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)
Index ¶
- Variables
- type Command
- type FileManager
- func (m *FileManager) EnableStaticGen(data StaticGen) error
- func (m FileManager) RootURL() string
- func (m FileManager) Runner(event string, path string) error
- func (m *FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (m *FileManager) SetBaseURL(url string)
- func (m *FileManager) SetPrefixURL(url string)
- type Hugo
- func (h Hugo) Hook(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error)
- func (h *Hugo) Preview(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error)
- func (h Hugo) Publish(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error)
- func (h Hugo) SettingsPath() string
- type Jekyll
- func (j Jekyll) Hook(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error)
- func (j *Jekyll) Preview(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error)
- func (j Jekyll) Publish(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error)
- func (j Jekyll) SettingsPath() string
- type Regexp
- type RequestContext
- type Rule
- type StaticGen
- type User
Constants ¶
This section is empty.
Variables ¶
var DefaultUser = User{ AllowCommands: true, AllowEdit: true, AllowNew: true, AllowPublish: true, Commands: []string{}, Rules: []*Rule{}, CSS: "", Admin: true, Locale: "en", FileSystem: fileutils.Dir("."), }
DefaultUser is used on New, when no 'base' user is provided.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command func(r *http.Request, m *FileManager, u *User) error
Command is a command function.
type FileManager ¶
type FileManager struct { // PrefixURL is a part of the URL that is already trimmed from the request URL before it // arrives to our handlers. It may be useful when using File Manager as a middleware // such as in caddy-filemanager plugin. It is only useful in certain situations. PrefixURL string // BaseURL is the path where the GUI will be accessible. It musn't end with // a trailing slash and mustn't contain PrefixURL, if set. It shouldn't be // edited directly. Use SetBaseURL. BaseURL string // NoAuth disables the authentication. When the authentication is disabled, // there will only exist one user, called "admin". NoAuth bool // StaticGen is the static websit generator handler. StaticGen StaticGen // The Default User needed to build the New User page. DefaultUser *User // Users is a map with the different configurations for each user. Users map[string]*User // A map of events to a slice of commands. Commands map[string][]string // contains filtered or unexported fields }
FileManager is a file manager instance. It should be creating using the 'New' function and not directly.
func New ¶
func New(database string, base User) (*FileManager, error)
New creates a new File Manager instance. If 'database' file already exists, it will load the users from there. Otherwise, a new user will be created using the 'base' variable. The 'base' User should not have the Password field hashed.
func (*FileManager) EnableStaticGen ¶ added in v1.2.0
func (m *FileManager) EnableStaticGen(data StaticGen) error
EnableStaticGen attaches a static generator to the current File Manager instance.
func (FileManager) RootURL ¶
func (m FileManager) RootURL() string
RootURL returns the actual URL where File Manager interface can be accessed.
func (FileManager) Runner ¶
func (m FileManager) Runner(event string, path string) error
Runner runs the commands for a certain event type.
func (*FileManager) ServeHTTP ¶
func (m *FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles the request.
func (*FileManager) SetBaseURL ¶
func (m *FileManager) SetBaseURL(url string)
SetBaseURL updates the baseURL of a File Manager object.
func (*FileManager) SetPrefixURL ¶
func (m *FileManager) SetPrefixURL(url string)
SetPrefixURL updates the prefixURL of a File Manager object.
type Hugo ¶ added in v1.2.0
type Hugo struct { // Website root Root string `name:"Website Root"` // Public folder Public string `name:"Public Directory"` // Hugo executable path Exe string `name:"Hugo Executable"` // Hugo arguments Args []string `name:"Hugo Arguments"` // Indicates if we should clean public before a new publish. CleanPublic bool `name:"Clean Public"` // contains filtered or unexported fields }
Hugo is the Hugo static website generator.
func (Hugo) Hook ¶ added in v1.2.0
func (h Hugo) Hook(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error)
Hook is the pre-api handler.
func (*Hugo) Preview ¶ added in v1.2.0
func (h *Hugo) Preview(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error)
Preview handles the preview path.
func (Hugo) Publish ¶ added in v1.2.0
func (h Hugo) Publish(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error)
Publish publishes a post.
func (Hugo) SettingsPath ¶ added in v1.2.0
SettingsPath retrieves the correct settings path.
type Jekyll ¶ added in v1.2.0
type Jekyll struct { // Website root Root string `name:"Website Root"` // Public folder Public string `name:"Public Directory"` // Jekyll executable path Exe string `name:"Executable"` // Jekyll arguments Args []string `name:"Arguments"` // Indicates if we should clean public before a new publish. CleanPublic bool `name:"Clean Public"` // contains filtered or unexported fields }
Jekyll is the Jekyll static website generator.
func (Jekyll) Hook ¶ added in v1.2.0
func (j Jekyll) Hook(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error)
Hook is the pre-api handler.
func (*Jekyll) Preview ¶ added in v1.2.0
func (j *Jekyll) Preview(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error)
Preview handles the preview path.
func (Jekyll) Publish ¶ added in v1.2.0
func (j Jekyll) Publish(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error)
Publish publishes a post.
func (Jekyll) SettingsPath ¶ added in v1.2.0
SettingsPath retrieves the correct settings path.
type Regexp ¶
type Regexp struct { Raw string `json:"raw"` // contains filtered or unexported fields }
Regexp is a regular expression wrapper around native regexp.
func (*Regexp) MatchString ¶
MatchString checks if this string matches the regular expression.
type RequestContext ¶
type RequestContext struct { *FileManager User *User File *file // On API handlers, Router is the APi handler we want. Router string }
RequestContext contains the needed information to make handlers work.
type Rule ¶
type Rule struct { // Regex indicates if this rule uses Regular Expressions or not. Regex bool `json:"regex"` // Allow indicates if this is an allow rule. Set 'false' to be a disallow rule. Allow bool `json:"allow"` // Path is the corresponding URL path for this rule. Path string `json:"path"` // Regexp is the regular expression. Only use this when 'Regex' was set to true. Regexp *Regexp `json:"regexp"` }
Rule is a dissalow/allow rule.
type StaticGen ¶ added in v1.2.0
type StaticGen interface { SettingsPath() string Hook(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error) Preview(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error) Publish(c *RequestContext, w http.ResponseWriter, r *http.Request) (int, error) }
StaticGen is a static website generator.
type User ¶
type User struct { // ID is the required primary key with auto increment0 ID int `storm:"id,increment"` // Username is the user username used to login. Username string `json:"username" storm:"index,unique"` // The hashed password. This never reaches the front-end because it's temporarily // emptied during JSON marshall. Password string `json:"password"` // Tells if this user is an admin. Admin bool `json:"admin"` // FileSystem is the virtual file system the user has access. FileSystem fileutils.Dir `json:"filesystem"` // Rules is an array of access and deny rules. Rules []*Rule `json:"rules"` // Custom styles for this user. CSS string `json:"css"` // Locale is the language of the user. Locale string `json:"locale"` // These indicate if the user can perform certain actions. AllowNew bool `json:"allowNew"` // Create files and folders AllowEdit bool `json:"allowEdit"` // Edit/rename files AllowCommands bool `json:"allowCommands"` // Execute commands AllowPublish bool `json:"allowPublish"` // Publish content (to use with static gen) // Commands is the list of commands the user can execute. Commands []string `json:"commands"` }
User contains the configuration for each user.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
caddy
|
|
filemanager
Package filemanager provides middleware for managing files in a directory when directory path is requested instead of a specific file.
|
Package filemanager provides middleware for managing files in a directory when directory path is requested instead of a specific file. |
cmd
|
|