Documentation ¶
Overview ¶
Package jantar is a lightweight mvc web framework with emphasis on security written in golang.
It has been largely inspired by Martini(https://github.com/codegangsta/martini) but prefers performance over syntactic sugar and aims to provide crucial security settings and features right out of the box.
Index ¶
- Constants
- Variables
- func ErrorHandler(status int) func(http.ResponseWriter, *http.Request)
- func GetModule(key int) interface{}
- func SecureCookie(usertoken string, data string) *http.Cookie
- func UnlockCookie(cookie *http.Cookie) *http.Cookie
- type Config
- type Controller
- type IController
- type IMiddleware
- type JLData
- type JLogger
- func (l *JLogger) Debug(v ...interface{})
- func (l *JLogger) Debugd(data JLData, v ...interface{})
- func (l *JLogger) Debugdf(data JLData, format string, v ...interface{})
- func (l *JLogger) Debugf(format string, v ...interface{})
- func (l *JLogger) Error(v ...interface{})
- func (l *JLogger) Errord(data JLData, v ...interface{})
- func (l *JLogger) Errordf(data JLData, format string, v ...interface{})
- func (l *JLogger) Errorf(format string, v ...interface{})
- func (l *JLogger) Fatal(v ...interface{})
- func (l *JLogger) Fatald(data JLData, v ...interface{})
- func (l *JLogger) Fataldf(data JLData, format string, v ...interface{})
- func (l *JLogger) Fatalf(format string, v ...interface{})
- func (l *JLogger) Info(v ...interface{})
- func (l *JLogger) Infod(data JLData, v ...interface{})
- func (l *JLogger) Infodf(data JLData, format string, v ...interface{})
- func (l *JLogger) Infof(format string, v ...interface{})
- func (l *JLogger) Panic(v ...interface{})
- func (l *JLogger) Panicd(data JLData, v ...interface{})
- func (l *JLogger) Panicdf(data JLData, format string, v ...interface{})
- func (l *JLogger) Panicf(format string, v ...interface{})
- func (l *JLogger) SetMinLevel(minLevel uint)
- func (l *JLogger) Warning(v ...interface{})
- func (l *JLogger) Warningd(data JLData, v ...interface{})
- func (l *JLogger) Warningdf(data JLData, format string, v ...interface{})
- func (l *JLogger) Warningf(format string, v ...interface{})
- type Jantar
- type Middleware
- type TLSConfig
- type TemplateManager
Constants ¶
const ( LogLevelDebug = iota LogLevelInfo = iota LogLevelWarning = iota LogLevelError = iota LogLevelFatal = iota LogLevelPanic = iota )
Defines the various logging level
const ( ModuleTemplateManager = iota ModuleRouter = iota )
Constants for accessing jantars core modules
const ( TmBeforeParse = iota TmBeforeRender = iota )
TemplateManager hooks
const ( TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 uint16 = 0xc02c TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 uint16 = 0xc030 TLS_RSA_WITH_AES_128_CBC_SHA256 uint16 = 0x003c TLS_RSA_WITH_AES_256_CBC_SHA256 uint16 = 0x003d TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 uint16 = 0xc023 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 uint16 = 0xc027 )
Additional TLS cipher
Variables ¶
var ( ErrHookDuplicateID = errors.New("id already in use") ErrHookUnknownID = errors.New("unknown hook Id") ErrHookInvalidHandler = errors.New("handler is not a function") )
Hook error codes
var StatusHandler map[int]func(http.ResponseWriter, *http.Request)
StatusHandler is a map containing a http.HandlerFunc for each client side http status code. This allows developer to add their own custom http.HandlerFunc for given status codes.
Functions ¶
func ErrorHandler ¶
func ErrorHandler(status int) func(http.ResponseWriter, *http.Request)
ErrorHandler returns a http.HandlerFunc for a given http status code or nil if no handler can be found for that code. Developer can add their own handler by changing the StatusHandler map. Note that only 4xx codes are handled by default as 1xx, 2xx and 3xx are no error codes and 5xx should not be catchable.
func GetModule ¶
func GetModule(key int) interface{}
GetModule returns the module specified by key. Returns nil for an invalid key
func SecureCookie ¶
SecureCookie saves given data in an AES256 encrypted and HMAC(SHA256) signed cookie
Types ¶
type Controller ¶
type Controller struct { Respw http.ResponseWriter Req *http.Request RenderArgs map[string]interface{} // contains filtered or unexported fields }
Controller implements core functionalities of the IController interface
func (*Controller) Redirect ¶
func (c *Controller) Redirect(to string, args ...interface{})
Redirect redirects the current request to a given named route using args to complete url variables
func (*Controller) Render ¶
func (c *Controller) Render()
Render gets the template for the calling action and renders it
func (*Controller) UrlParam ¶
func (c *Controller) UrlParam() map[string]string
type IController ¶
type IController interface { Render() // contains filtered or unexported methods }
IController describes a Controller
type IMiddleware ¶
type IMiddleware interface { Initialize() Cleanup() Call(rw http.ResponseWriter, r *http.Request) bool Yield(rw http.ResponseWriter, r *http.Request) // contains filtered or unexported methods }
IMiddleware is an interface that describes a Middleware
type JLData ¶
type JLData map[string]interface{}
JLData is a type describing map that can be passed to Data<Level>f functions for debug output
type JLogger ¶
type JLogger struct {
// contains filtered or unexported fields
}
JLogger is a simple Log with some handy functions. Largely inspired by https://github.com/Sirupsen/logrus
func NewJLogger ¶
NewJLogger creates a new JLogger instance
func (*JLogger) Debug ¶
func (l *JLogger) Debug(v ...interface{})
Debug is equivalent to Info but uses a different logging level
func (*JLogger) Error ¶
func (l *JLogger) Error(v ...interface{})
Error is equivalent to Info but uses a different logging level
func (*JLogger) Fatal ¶
func (l *JLogger) Fatal(v ...interface{})
Fatal is equivalent to Info but uses a different logging level and calls fatal afterwards
func (*JLogger) Fatald ¶
Fatald is equivalent to Infod but uses a different logging level and calls fatal afterwards
func (*JLogger) Fataldf ¶
Fataldf is equivalent to Infodf but uses a different logging level and calls fatal afterwards
func (*JLogger) Fatalf ¶
Fatalf is equivalent to Infof but uses a different logging level and calls fatal afterwards
func (*JLogger) Info ¶
func (l *JLogger) Info(v ...interface{})
Info is similar to log.Print but uses a special markup indicating the message severity
func (*JLogger) Infof ¶
Infof is similar to log.Printf but uses a special markup indicating the message severity
func (*JLogger) Panic ¶
func (l *JLogger) Panic(v ...interface{})
Panic is equivalent to Info but uses a different logging level and calls panic afterwards
func (*JLogger) Panicd ¶
Panicd is equivalent to Infod but uses a different logging level and calls panic afterwards
func (*JLogger) Panicdf ¶
Panicdf is equivalent to Infodf but uses a different logging level and calls fatal afterwards
func (*JLogger) Panicf ¶
Panicf is equivalent to Infof but uses a different logging level and calls panic afterwards
func (*JLogger) SetMinLevel ¶
SetMinLevel changes the loggers current minimal logging level
func (*JLogger) Warning ¶
func (l *JLogger) Warning(v ...interface{})
Warning is equivalent to Info but uses a different logging level
type Jantar ¶
type Jantar struct {
// contains filtered or unexported fields
}
Jantar is the top level application type
func New ¶
New creates a new Jantar instance ready to listen on a given hostname and port. Choosing a port small than 1 will cause Jantar to use the standard ports.
func (*Jantar) AddMiddleware ¶
func (j *Jantar) AddMiddleware(mware IMiddleware)
AddMiddleware adds a given middleware to the current middleware list. Middlewares are executed once for every request before the actual route handler is called
func (*Jantar) AddRoute ¶
AddRoute adds a route with given method, pattern and handler to the Router
func (*Jantar) Run ¶
func (j *Jantar) Run()
Run starts the http server and listens on the hostname and port given to New
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware implements core functionalities of the IMiddlware interface. Developer who want to write a Middleware should add Middleware as an anonymous field and implement Call().
func (*Middleware) Yield ¶
func (m *Middleware) Yield(rw http.ResponseWriter, r *http.Request)
Yield suspends the current Middlware until all other Middlewares have been executed. This way a Middleware can execute code after all other Middlewares are done
type TLSConfig ¶
type TLSConfig struct { CertFile string KeyFile string CertPem []byte KeyPem []byte // contains filtered or unexported fields }
TLSConfig can be given to Jantar to enable tls support
type TemplateManager ¶
type TemplateManager struct {
// contains filtered or unexported fields
}
TemplateManager is responsible for loading, watching and rendering templates
func (*TemplateManager) AddTmplFunc ¶
func (tm *TemplateManager) AddTmplFunc(name string, fn interface{})
AddTmplFunc adds a template function with a given name and function pointer. Note: AddTmplFunc has no effect if called after the templates have been parsed.
func (*TemplateManager) RenderTemplate ¶
func (tm *TemplateManager) RenderTemplate(w io.Writer, req *http.Request, name string, args map[string]interface{}) error
RenderTemplate renders a template with the given name and arguments. Note: A Controller should call its Render function instead.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package context is a small package for arbitrary per-request, global data and modules Module data are set by jantar and are read-only by default.
|
Package context is a small package for arbitrary per-request, global data and modules Module data are set by jantar and are read-only by default. |