server

package
v0.0.0-...-c5e702e Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2018 License: ISC Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UseLog

func UseLog(_log *logrus.Logger)

UseLog sets an external logger for use by this package.

Types

type PageTemplate

type PageTemplate struct {
	// contains filtered or unexported fields
}

PageTemplate associates a template file with an http/template.Template

type Server

type Server struct {
	CookieStore   *sessions.FilesystemStore
	AuthToken     *jwtauth.JWTAuth
	SigningKey    string
	MaxFileSize   int64
	FilesPath     string
	Templates     *SiteTemplates
	UserFileStore *storm.DB
}

Server manages cookies/auth, and implements the http handlers

func NewServer

func NewServer(secret, cookieStorePath string, maxFileSize int64) (*Server, error)

NewServer creates a new Server for the given signing secret, cookie storage file system path, and uploaded file size limit.

func (*Server) File

func (s *Server) File(w http.ResponseWriter, r *http.Request)

File is the handler for file downloads, requiring the "{fileid}" URL path parameter (e.g. /file/{fileid}).

func (*Server) FileList

func (s *Server) FileList(w http.ResponseWriter, r *http.Request)

FileList generates a response containing a JSON array of file UIDs that the user is permitted to access.

func (*Server) Shutdown

func (s *Server) Shutdown() error

Shutdown cleanly shutsdown the Server

func (*Server) Token

func (s *Server) Token(w http.ResponseWriter, r *http.Request)

Token returns the user/session's current JWT.

func (*Server) UIDToFilePath

func (s *Server) UIDToFilePath(UID string, mkdir bool) (string, int, error)

UIDToFilePath looks up the file name for the file with unique identifier UID, and returns the absolute path to the files, a http status code, and an error.

func (*Server) UploadFile

func (s *Server) UploadFile(w http.ResponseWriter, r *http.Request)

UploadFile is the upload handler for POST requests with the file data stored in the body with Content-Type multipart/form-data.

func (*Server) WithJWTCookie

func (s *Server) WithJWTCookie(next http.Handler) http.Handler

WithJWTCookie injects a new or existing cookie-managed JWT into the request context. The signed token and the session are both embedded.

func (*Server) WithSession

func (s *Server) WithSession(next http.Handler) http.Handler

WithSession injects a new or existing cookie-managed session into the request context.

func (*Server) WithUserFileAuthz

func (s *Server) WithUserFileAuthz(next http.Handler) http.Handler

WithUserFileAuthz checks the permission of CtxUser for the file being accessed.

type SiteTemplates

type SiteTemplates struct {
	// contains filtered or unexported fields
}

SiteTemplates contains all of the PageTemplates used by webfiles, as well as the template.FuncMap used in their execution.

func NewTemplates

func NewTemplates(folder string, names []string, helpers template.FuncMap) (*SiteTemplates, error)

NewTemplates parses all of the named templates in the given folder. The file names are obtained by concatenating ".tmpl" to the tamplate name.

func (*SiteTemplates) ExecTemplate

func (t *SiteTemplates) ExecTemplate(w http.ResponseWriter, name string, data interface{}) error

ExecTemplate executes the specified template using the supplied data, and writes the result directly to the ResponseWriter.

func (*SiteTemplates) ExecTemplateToString

func (t *SiteTemplates) ExecTemplateToString(name string, data interface{}) (string, error)

ExecTemplateToString executes the specified template using the supplied data, and writes the result into a string. If the template fails to execute or isn't found, a non-nil error will be returned.

type UserFileStoreItem

type UserFileStoreItem struct {
	RowID  int    `storm:"id,increment"`
	User   string `storm:"index"`
	FileID int64  `storm:"index"`
}

UserFileStoreItem is the type in the storm user-file DB.

type WebMux

type WebMux struct {
	*chi.Mux
}

WebMux is the http path multiplexer

func NewRouter

func NewRouter(server *Server) WebMux

NewRouter creates a new WebMux for the specified Server. This configures the middleware, and the route mapping.

Jump to

Keyboard shortcuts

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