vincent

package module
v0.0.0-...-6b086db Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2016 License: MIT Imports: 13 Imported by: 0

README

Vincent

Vincent

Build Status Coverage Status Go Report Card

Vincent is a lightweight golang Web framework. Following the MVC pattern, you can quickly and easily create dynamic websites using Golang and Handlebars.

Usage


import "github.com/tomdionysus/vincent"

Getting Started

Please see vincent-demo for a complete example.

License

vincent is licensed under the Open Source MIT license. Please see the License File for more details.

Code Of Conduct

The vincent project supports and enforces The Contributor Covenant. Please read the code of conduct before contributing.

Documentation

Overview

Vincent is a lightweight Web framework for golang. Templates are written using Handlebars, and it supports routing and TLS.

For an example of use, please see http://github.com/tomdionysus/vincent-demo

Index

Constants

View Source
const VERSION = "0.0.1"

Variables

This section is empty.

Functions

func NewConnLimitListener

func NewConnLimitListener(count int, l *net.TCPListener) net.Listener

Return a new ConnLimitListener using the supplied connection limit and underlying TCPListener

Types

type BufferedResponseWriter

type BufferedResponseWriter struct {
	Headers    http.Header
	Buffer     *bytes.Buffer
	StatusCode int
}

A ResponseWriter that buffers everything written to it

func NewBufferedResponseWriter

func NewBufferedResponseWriter() *BufferedResponseWriter

Return a new BufferedResponseWriter

func (*BufferedResponseWriter) FlushToResponseWriter

func (brw *BufferedResponseWriter) FlushToResponseWriter(w http.ResponseWriter) error

Write HTTP Status, Headers and Flush all data to the supplied http.ResponseWriter

func (*BufferedResponseWriter) Header

func (brw *BufferedResponseWriter) Header() http.Header

Return the current headers

func (*BufferedResponseWriter) Write

func (brw *BufferedResponseWriter) Write(data []byte) (int, error)

Write the supplied data

func (*BufferedResponseWriter) WriteHeader

func (brw *BufferedResponseWriter) WriteHeader(code int)

Set the HTTP status code

type ConnLimitConn

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

A net.Conn for use with ConnLimitListener

func (*ConnLimitConn) Close

func (cll *ConnLimitConn) Close() error

Close the underlying connection

func (*ConnLimitConn) LocalAddr

func (cll *ConnLimitConn) LocalAddr() net.Addr

Return the LocalAddr of the underlying connection

func (*ConnLimitConn) Read

func (cll *ConnLimitConn) Read(b []byte) (int, error)

Read from the underlying connection

func (*ConnLimitConn) RemoteAddr

func (cll *ConnLimitConn) RemoteAddr() net.Addr

Return the RemoteAddr of the underlying connection

func (*ConnLimitConn) SetDeadline

func (cll *ConnLimitConn) SetDeadline(t time.Time) error

Set the timeout deadline of the underlying connection

func (*ConnLimitConn) SetReadDeadline

func (cll *ConnLimitConn) SetReadDeadline(t time.Time) error

Set the read timeout deadline of the underlying connection

func (*ConnLimitConn) SetWriteDeadline

func (cll *ConnLimitConn) SetWriteDeadline(t time.Time) error

Set the write timeout deadline of the underlying connection

func (*ConnLimitConn) Write

func (cll *ConnLimitConn) Write(b []byte) (int, error)

Write to the underlying connection

type ConnLimitListener

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

A TCPListener that limits concurrent connections

func (*ConnLimitListener) Accept

func (cll *ConnLimitListener) Accept() (net.Conn, error)

Block until a connection is available and the limit has not been reached, then accpt the connection and return it

func (*ConnLimitListener) Addr

func (cll *ConnLimitListener) Addr() net.Addr

Return the underlying listener Address

func (*ConnLimitListener) Close

func (cll *ConnLimitListener) Close() error

Close the underlying listener

type Context

type Context struct {
	Server *Server

	Request        *http.Request
	ResponseWriter http.ResponseWriter

	Params map[string]interface{}

	Input  map[string]interface{}
	Output map[string]interface{}
}

func NewContext

func NewContext(server *Server, w http.ResponseWriter, r *http.Request) *Context

type Controller

type Controller func(context *Context) (bool, error)

type FileSegment

type FileSegment struct {
	RouteSegment
	Filename string
}

A segment of a route that repcontext.ResponseWriterents a raw file

func NewFileSegment

func NewFileSegment(filename string) *FileSegment

Return a new FileSegment with the supplied filename

func (*FileSegment) Render

func (fsg *FileSegment) Render(path string, context *Context) (bool, error)

If the path refers to this segment, render the supplied path to the context.ResponseWriterponsewriter. Otherwise, passthrough to sub segments.

type Handler

type Handler interface {
	Render(path string, context *Context) (bool, error)
	Passthrough(path string, context *Context) (bool, error)
	Add(path string, handler Handler) error
	AddController(path string, controller Controller)
	CallControllers(context *Context) (bool, error)
	Walk(path string, fn RouteSegmentWalkFunc) bool
}

An interface that handles a Route segment

type HandlerFunc

type HandlerFunc func(path string, req *http.Request, res http.ResponseWriter, context map[string]interface{}) (bool, error)

A function that handle a route segment

type ParamSegment

type ParamSegment struct {
	RouteSegment
	ParamName string
}

A segment of a route that represents a parameter

func NewParamSegment

func NewParamSegment(paramName string) *ParamSegment

Return a new ParamSegment with the supplied name, e.g. "identity" or "identity.name"

func (*ParamSegment) Render

func (psg *ParamSegment) Render(path string, context *Context) (bool, error)

Load the current segment value into the context and passthrough.

type RouteSegment

type RouteSegment struct {
	Server      *Server
	Segments    map[string]Handler
	Controllers []Controller
}

Represents a single segment of a route, e.g. http://host:port/<segment>/<segment>...

func NewRouteSegment

func NewRouteSegment(svr *Server) *RouteSegment

Return a new RouteSegment for the supplied server

func (*RouteSegment) Add

func (rsg *RouteSegment) Add(path string, handler Handler) error

Add a route and handler to this segment at this segment's path

func (*RouteSegment) AddController

func (rsg *RouteSegment) AddController(path string, controller Controller)

func (*RouteSegment) CallControllers

func (rsg *RouteSegment) CallControllers(context *Context) (bool, error)

func (*RouteSegment) Passthrough

func (rsg *RouteSegment) Passthrough(path string, context *Context) (bool, error)

Process the path and call Render on subroute handlers

func (*RouteSegment) Render

func (rsg *RouteSegment) Render(path string, context *Context) (bool, error)

func (*RouteSegment) Walk

func (rsg *RouteSegment) Walk(path string, fn RouteSegmentWalkFunc) bool

Walk the segment tree calling the supplied RouteSegmentWalkFunc for each possible route leaf

type RouteSegmentWalkFunc

type RouteSegmentWalkFunc func(path, name string) bool

A function to walk the segment tree

type Server

type Server struct {
	Log log.Logger

	Root            *RouteSegment
	DefaultDocument string
}

Server is a HTTP server for use with vincent projects.

func New

func New(logger log.Logger) (*Server, error)

Return a new Server with the specified logger

func (*Server) AddController

func (svr *Server) AddController(path string, controller Controller)

func (*Server) LoadTemplates

func (svr *Server) LoadTemplates(routePrefix, basePath string) error

Walk the supplied basePath directory and parse all files and templates into routes using the route prefix specified.

func (*Server) ServeHTTP

func (svr *Server) ServeHTTP(wr http.ResponseWriter, r *http.Request)

Support the http.Handler ServeHTTP method. This is called once per request

func (*Server) Start

func (svr *Server) Start(addr string)

Start the HTTP server on the specified address and port, of format "<host>:<port>", e.g. "localhost:8080"

func (*Server) StartTLS

func (svr *Server) StartTLS(addr, certFile, keyFile string)

Start the HTTP server on the specified address and port, of format "<host>:<port>", e.g. "localhost:8080"

type TemplateSegment

type TemplateSegment struct {
	RouteSegment
	Template *raymond.Template
}

A Segment representing a handlebars template

func NewTemplateSegment

func NewTemplateSegment(template *raymond.Template) *TemplateSegment

Return a new TemplateSegment with the supplied raymond.Template

func (*TemplateSegment) Render

func (tsg *TemplateSegment) Render(path string, context *Context) (bool, error)

If the path ends with this segment, render the template using the supplied context to the responsewriter. Otherwise, passthrough to sub segments.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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