mngr

package module
v0.0.0-...-53c2ad7 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2017 License: MIT Imports: 11 Imported by: 0

README

mngr

This repo contains a file manager for Hugo website. This repo is under active developement and everything might change at any time.

Status

  • display folder's content
  • display file content
  • edit file content
  • create file
  • create folder
  • display folder's content recursively
  • create, view and edit file and folder recursively
  • add back button on list page
  • have a good look at / handling for folder
  • delete file
  • delete folder
  • render Markdown for .md only
  • parse pages with github.com/spf13/hugo/parser

Limitations

The current interface might not work with file and folders named after an action: /edit/, view, new, list. Not tested.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EditHandler

func EditHandler(w http.ResponseWriter, r *http.Request) (int, error)

EditHandler is an handler use to edit the content of a file.

func FolderHandler

func FolderHandler(w http.ResponseWriter, r *http.Request) (int, error)

FolderHandler is a HandlerFunc use to create new folder.

func MakeLogMiddleware

func MakeLogMiddleware(out io.Writer) func(h Handler) http.HandlerFunc

MakeLogMiddleware create a logging middleware who wan be plugged into the default Go http.Server. The middleware traces every request and handle the response if mngr.Handler return 0 and an error.

func NewFolder

func NewFolder(v ValidURL) error

func PagePathFromValidURL

func PagePathFromValidURL(v ValidURL) string

func SaveHandler

func SaveHandler(w http.ResponseWriter, r *http.Request) (int, error)

SaveHandler is an handler use to save the content of a page in a file.

func TemplateFromCtx

func TemplateFromCtx(c context.Context) (*template.Template, bool)

TemplateFromCtx extract templates added by MakeTemplateMiddleware to a context.

func ViewHandler

func ViewHandler(w http.ResponseWriter, r *http.Request) (int, error)

ViewHandler is an handler use to display the content of a file.

Types

type Handler

type Handler interface {
	ServeHTTP(http.ResponseWriter, *http.Request) (int, error)
}

Handler is like http.Handler except ServeHTTP may return a status code and/or error.

If ServeHTTP writes the response header, it should return a status code of 0. This signals to other handlers before it that the response is already handled, and that they should not write to it also. Keep in mind that writing to the response body writes the header, too.

If ServeHTTP encounters an error, it should return the error value so it can be logged by designated error-handling middleware.

If writing a response after calling the next ServeHTTP method, the returned status code SHOULD be used when writing the response.

If handling errors after calling the next ServeHTTP method, the returned error value SHOULD be logged or handled accordingly.

Otherwise, return values should be propagated down the middleware chain by returning them unchanged.

type HandlerFunc

type HandlerFunc func(http.ResponseWriter, *http.Request) (int, error)

HandlerFunc is a convenience type like http.HandlerFunc, except ServeHTTP returns a status code and an error. See Handler documentation for more information.

func MakeListHandler

func MakeListHandler(dataPath string) HandlerFunc

MakeListHandler return an handler wich list folder's content. The handler will list all the file present in dataPath.

func MakeNewHandler

func MakeNewHandler() HandlerFunc

MakeNewHandler return an HandlerFunc which deals with file and folder creation.

func (HandlerFunc) ServeHTTP

func (f HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)

ServeHTTP implements the Handler interface.

type Middleware

type Middleware func(Handler) Handler

Middleware is the middle layer which represents the traditional idea of middleware: it chains one Handler to the next by being passed the next Handler in the chain.

func MakeTemplateMiddleware

func MakeTemplateMiddleware(path string) Middleware

MakeTemplateMiddleware load an compile all templates located in 'path/*.html' and 'path/partial/*.html'. When plugged, the returned middleware add templates to the request's context.

func MakeValidFolderMiddleware

func MakeValidFolderMiddleware(dataPath string) Middleware

MakeValidFolderMiddleware create an URL validation middleware. When plugged, the returned middleware will look for a valid URL and an existing folder on disk. It will also add a ValidURL to the request's context.

func MakeValidURLMiddleware

func MakeValidURLMiddleware() Middleware

MakeValidURLMiddleware create an URL validation middleware. When plugged, the returned middleware add a ValidURL to the request's context.

type Page

type Page struct {
	TemplateInfo
	Path     string
	Filename string
	Body     []byte
}

Page represet a wiki page.

func LoadPage

func LoadPage(v ValidURL) (*Page, error)

func NewPage

func NewPage(v ValidURL, body []byte) *Page

type TemplateInfo

type TemplateInfo struct {
	Action string
	Value  string
	Dir    string
	IsDir  bool
}

TemplateInfo contains the field common to every template.

func NewTemplateFromValidURL

func NewTemplateFromValidURL(v ValidURL) TemplateInfo

type ValidURL

type ValidURL struct {
	// Action represent the action requested in the URL.
	// This field only support the values: edit, view, save
	Action string
	// Value contains the object on wich this action apply.
	// It must contain something of the form: 'filename.ext' of 'filename'
	Value string
	// Dir contains the name of the folder.
	Dir string
}

ValidURL represent a valid URL for our application.

func ValidURLFromCtx

func ValidURLFromCtx(ctx context.Context) (ValidURL, bool)

ValidURLFromCtx extract a ValidURL added by MakeValidURLMiddleware from a context.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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