enliven

package module
v0.0.0-...-a266510 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2017 License: BSD-3-Clause, MIT Imports: 9 Imported by: 1

README

Enliven

An easy-to-use web application framework in Go

Features:
  • Developed to deliver similar features to the "Django" framework (python)
  • Wraps and provides gorilla/mux for routing
  • Uses jinzhu/gorm for database management/interaction
  • Contains a fork of qor/admin, an administration panel (similar to Django w/ Suit)
  • Middleware management inspired by codegangsta/negroni
  • Dependency Injection via context provided to handlers/middleware
  • Session management with multiple storage drivers
  • User account management, including user roles and permissions
  • Static asset serving via true filesystem or embedded assets using Statik
  • API for writing packaged enliven "apps" which can be easily added to any Enliven app
Project State
Enliven is mainly a personal project custom tailored to my personal desires/needs.
As such, I consider this a production-ready, mature project, and currently have some
closed-source projects which are presently using it. I don't see myself writing a
whole pile of documentation for it unless it magically gains a following and users
request documentation.
Future updates will consist of features I want to add to the framework in addition
to bug fixes, etc. Again, I'm totally open to adding requested features as well,
though that would require the aforementioned magical following gains.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultEnlivenConfig = config.Config{
	"email_smtp_identity":  "",
	"email_smtp_username":  "",
	"email_smtp_password":  "",
	"email_smtp_host":      "",
	"email_smtp_port":      "25",
	"email_from_default":   "",
	"email_smtp_auth":      "plain",
	"email_allow_insecure": "0",

	"server_address": ":8000",

	"site_name": "Enliven",
	"site_url":  "http://localhost:8000",
}

DefaultEnlivenConfig represents the default config for enliven

Functions

This section is empty.

Types

type CHandler

type CHandler func(*Context)

CHandler Handles injecting the initial request context before passing handling on to the Middleware struct

func ContextHandler

func ContextHandler(h Middleware) CHandler

ContextHandler sets up serving the first request, and the handing off of subsequent requests to the Middleware struct

func (CHandler) ServeHTTP

func (ch CHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request)

ServeHTTP is the first handler that gets hit when a request comes in.

type Context

type Context struct {
	Session  ISession
	Vars     map[string]string // This map specifically to hold route key value pairs.
	Strings  map[string]string
	Integers map[string]int
	Booleans map[string]bool
	Storage  map[string]interface{}
	Enliven  *Enliven
	Response http.ResponseWriter
	Request  *http.Request
}

Context stores context variables and the session that will be passed to requests

func (*Context) AnonymousTemplate

func (ctx *Context) AnonymousTemplate(tmpl *template.Template)

AnonymousTemplate sets up HTML headers and outputs an html/template response

func (*Context) BadRequest

func (ctx *Context) BadRequest()

BadRequest returns a 400 status and the bad-request page

func (*Context) EmptyOK

func (ctx *Context) EmptyOK()

EmptyOK outputs a 200 status with nothing else

func (*Context) ExecuteBaseTemplate

func (ctx *Context) ExecuteBaseTemplate(templateName string)

ExecuteBaseTemplate sets up HTML headers and outputs an html/template response for a specific template definition

func (*Context) ExecuteTemplate

func (ctx *Context) ExecuteTemplate(templateName string)

ExecuteTemplate gets a specific template from our list of templates and executes it

func (*Context) Forbidden

func (ctx *Context) Forbidden()

Forbidden returns a 403 status and the forbidden page.

func (*Context) HTML

func (ctx *Context) HTML(output string)

HTML sets up HTML headers and outputs a string response

func (*Context) JSON

func (ctx *Context) JSON(output []byte)

JSON sets up JSON headers and outputs a JSON response Expects to recieve the result of json marshalling ([]byte)

func (*Context) NotFound

func (ctx *Context) NotFound()

NotFound returns a 404 status and the not-found page

func (*Context) Redirect

func (ctx *Context) Redirect(location string, status ...int)

Redirect is a shortcut for redirecting a browser to a new URL

func (*Context) String

func (ctx *Context) String(output string)

String sets up string headers and outputs a string response

type DefaultAuth

type DefaultAuth struct{}

DefaultAuth is a simple implementation of IAuthorizer to stand in for auth checking/adding This should be overridden by the user app or something else if permissions checking is needed.

func (*DefaultAuth) AddPermission

func (da *DefaultAuth) AddPermission(permission string, ev *Enliven, groups ...string)

AddPermission is the default permission adder, and does nothing.

func (*DefaultAuth) HasPermission

func (da *DefaultAuth) HasPermission(permission string, ctx *Context) bool

HasPermission is the default permission checker and always returns true

type Enliven

type Enliven struct {
	Auth   IAuthorizer
	Core   core.Core
	Router *mux.Router
	// contains filtered or unexported fields
}

Enliven is....Enliven

func New

func New(conf config.Config) *Enliven

New gets a new instance of enliven.

func (*Enliven) AddApp

func (ev *Enliven) AddApp(app IApp)

AddApp initializes a provided enliven application

func (*Enliven) AddMiddleware

func (ev *Enliven) AddMiddleware(handler IMiddlewareHandler)

AddMiddleware adds a Handler onto the middleware stack. Copied w/ alterations from github.com/codegangsta/negroni

func (*Enliven) AddMiddlewareFunc

func (ev *Enliven) AddMiddlewareFunc(handlerFunc func(*Context, NextHandlerFunc))

AddMiddlewareFunc adds a HandlerFunc onto the middleware stack. Copied w/ alterations from github.com/codegangsta/negroni

func (*Enliven) AddRoute

func (ev *Enliven) AddRoute(path string, rhf func(*Context), methods ...string) *mux.Route

AddRoute Registers a handler for a given route. We register a dummy route with mux, and then store the provided handler which we'll use later in order to inject dependencies into the handler func.

func (*Enliven) AddService

func (ev *Enliven) AddService(name string, service interface{})

AddService registers an enliven service or dependency

func (*Enliven) AppInstalled

func (ev *Enliven) AppInstalled(name string) bool

AppInstalled returns true if a given app has already been installed

func (*Enliven) GetService

func (ev *Enliven) GetService(name string) interface{}

GetService returns an enliven service or dependency

func (*Enliven) MiddlewareInstalled

func (ev *Enliven) MiddlewareInstalled(name string) bool

MiddlewareInstalled returns true if a given middleware has already been installed

func (*Enliven) Run

func (ev *Enliven) Run()

Run executes the Enliven http server

type HandlerFunc

type HandlerFunc func(*Context, NextHandlerFunc)

HandlerFunc allow use of ordinary functions middleware handlers Copied w/ alterations from github.com/codegangsta/negroni

func (HandlerFunc) GetName

func (h HandlerFunc) GetName() string

GetName returns an empty string for this function middleware

func (HandlerFunc) Initialize

func (h HandlerFunc) Initialize(ev *Enliven)

Initialize initializes this function middleware by doing nothing

func (HandlerFunc) ServeHTTP

func (h HandlerFunc) ServeHTTP(ctx *Context, next NextHandlerFunc)

Copied w/ alterations from github.com/codegangsta/negroni

type IApp

type IApp interface {
	Initialize(*Enliven)
	GetName() string
}

IApp is an interface for writing Enliven apps Apps are basically packaged code to extend Enliven's functionality

type IAuthorizer

type IAuthorizer interface {
	HasPermission(string, *Context) bool
	// Name of the new permission, the enliven instance, groups that we want to add permission to
	AddPermission(string, *Enliven, ...string)
}

IAuthorizer is an interface to be used when writing a struct for checking a permission

type IMiddlewareHandler

type IMiddlewareHandler interface {
	Initialize(*Enliven)
	GetName() string
	ServeHTTP(*Context, NextHandlerFunc)
}

IMiddlewareHandler is an interface to be used when writing Middleware Copied w/ alterations from github.com/codegangsta/negroni

type ISession

type ISession interface {
	Set(key string, value string) error
	Get(key string) string
	Delete(key string) error
	Destroy() error
	SessionID() string
}

ISession represents a session that session middleware must implement

type Middleware

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

Middleware Represents a piece of middlewear Copied w/ alterations from github.com/codegangsta/negroni

func (Middleware) ServeHTTP

func (m Middleware) ServeHTTP(ctx *Context)

Copied w/ alterations from github.com/codegangsta/negroni

type NextHandlerFunc

type NextHandlerFunc func(*Context)

NextHandlerFunc allow use of ordinary functions middleware handlers Copied w/ alterations from github.com/codegangsta/negroni

func (NextHandlerFunc) ServeHTTP

func (nh NextHandlerFunc) ServeHTTP(ctx *Context)

Copied w/ alterations from github.com/codegangsta/negroni

type RouteHandlerFunc

type RouteHandlerFunc func(*Context)

RouteHandlerFunc is an interface to be used when writing route handler functions

Directories

Path Synopsis
middleware

Jump to

Keyboard shortcuts

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