Documentation
¶
Index ¶
- Constants
- Variables
- func AddFunc(key string, fn interface{})
- func ConcatenateCSS(paths []string) []byte
- func DecodeCookie(key []byte, maxlifetime int, signedValue string, req *http.Request) (string, error)
- func EncodeCookie(key []byte, sessionID string, req *http.Request) string
- func GetSessionID(r *http.Request, name string) string
- func GetTemplateFuncs() template.FuncMap
- func MinifyCSS(css []byte) string
- func MinifyHTML(html []byte) string
- func MinifyJS(js []byte) string
- func Mode() string
- func NewSessionID() string
- func RegisterController(c Controller)
- func RegisterGRPCService(s GRPCServices)
- func RemoveCSSComments(content []byte) []byte
- func RemoveHTMLComments(content []byte) []byte
- func Run()
- func RunGRPC()
- func RunTLS()
- func ServerStreamInterceptor() grpc.StreamServerInterceptor
- func ServerUnaryInterceptor() grpc.UnaryServerInterceptor
- func SetGoogleAnalytics(code string)
- func SetMode(value string)
- func Use(filter HandlerFunc)
- func UseGRPCStreamInterceptor(filter grpc.StreamServerInterceptor)
- func UseGRPCUnaryInterceptor(filter grpc.UnaryServerInterceptor)
- type BaseController
- func (c *BaseController) Any(pattern string, handlers ...HandlerFunc)
- func (c *BaseController) DELETE(pattern string, handlers ...HandlerFunc)
- func (c *BaseController) GET(pattern string, handlers ...HandlerFunc)
- func (c *BaseController) HEAD(pattern string, handlers ...HandlerFunc)
- func (c *BaseController) OPTIONS(pattern string, handlers ...HandlerFunc)
- func (c *BaseController) PATCH(pattern string, handlers ...HandlerFunc)
- func (c *BaseController) POST(pattern string, handlers ...HandlerFunc)
- func (c *BaseController) PUT(pattern string, handlers ...HandlerFunc)
- func (c *BaseController) Route(pattern string, method string, handler HandlerFunc)
- type BeforeFunc
- type BodyPart
- type ConfigData
- type Configuration
- type Context
- func (c *Context) AddShared(key string, value interface{})
- func (c *Context) Error(code int, err error)
- func (c *Context) GetFlash() (map[string]string, error)
- func (c *Context) GetShared(key string) interface{}
- func (c *Context) Header(key, value string)
- func (c *Context) JSON(code int, obj interface{})
- func (c *Context) Meta(key, value string)
- func (c *Context) ParseForm() error
- func (c *Context) ParseJSON(v interface{}) error
- func (c *Context) Plain(code int, s string)
- func (c *Context) Redirect(status int, url string)
- func (c *Context) Render(name string)
- func (c *Context) Reset()
- func (c *Context) WriteFlash(fd *FlashData) error
- type ContextPool
- type Controller
- type Email
- func (m *Email) Attach(filename, path string)
- func (m *Email) Bcc(emails ...string)
- func (m *Email) ClearAttachments()
- func (m *Email) From(addr string)
- func (m *Email) FromName(name string)
- func (m *Email) HTML() *BodyPart
- func (m *Email) Plain() *BodyPart
- func (m *Email) ReplyTo(addr string)
- func (m *Email) Send() error
- func (m *Email) Subject(subject string)
- func (m *Email) To(emails ...string)
- type Emailer
- type Engine
- type FileSessionProvider
- func (fsp *FileSessionProvider) Delete(key string) error
- func (fsp *FileSessionProvider) Destroy() error
- func (fsp *FileSessionProvider) GC()
- func (fsp *FileSessionProvider) Get(key string) interface{}
- func (fsp *FileSessionProvider) Handler(c *Context)
- func (fsp *FileSessionProvider) Init(rw http.ResponseWriter, r *http.Request) (Session, error)
- func (fsp *FileSessionProvider) Release(rw http.ResponseWriter, req *http.Request)
- func (fsp *FileSessionProvider) SessionID() string
- func (fsp *FileSessionProvider) Set(key string, value interface{}) error
- type FlashData
- type GRPCServer
- type GRPCService
- type GRPCServices
- type HandlerFunc
- type JSON
- type JSONData
- type JSONValue
- type Level
- type Logger
- func (l *Logger) Critical(str string)
- func (l *Logger) Criticalf(format string, a ...interface{})
- func (l *Logger) Debug(str string)
- func (l *Logger) Debugf(format string, a ...interface{})
- func (l *Logger) Error(err error)
- func (l *Logger) Errorf(format string, a ...interface{})
- func (l *Logger) Info(str string)
- func (l *Logger) Infof(format string, a ...interface{})
- func (l *Logger) Warning(str string)
- func (l *Logger) Warningf(format string, a ...interface{})
- type Renderer
- type Request
- type ResponseWriter
- type Route
- type Router
- type Routes
- type Rule
- type Session
- type SessionConfig
- type SessionProvider
- type Validator
- func (v *Validator) Alpha(value string) bool
- func (v *Validator) AlphaNumeric(value string) bool
- func (v *Validator) Base64(value string) bool
- func (v *Validator) Bool(value interface{}) bool
- func (v *Validator) Email(value string) bool
- func (v *Validator) Exact(value int, compare int) bool
- func (v *Validator) ExactLength(value string, length int) bool
- func (v *Validator) Float(value string) bool
- func (v *Validator) Float64(value interface{}) bool
- func (v *Validator) IP(value string) bool
- func (v *Validator) Max(value int, max int) bool
- func (v *Validator) MaxLength(value string, max int) bool
- func (v *Validator) Min(value int, min int) bool
- func (v *Validator) MinLength(value string, min int) bool
- func (v *Validator) Numeric(value string) bool
- func (v *Validator) Required(value interface{}) bool
- func (v *Validator) Rule(field string, label string, rule string, errorMessage string)
- func (v *Validator) Rules(field string, label string, rules []string, errorMessages []string)
- func (v *Validator) String(value interface{}) bool
- func (v *Validator) URL(value string) bool
- func (v *Validator) Valid(values map[string]interface{}) error
- func (v *Validator) ValidForm() error
- func (v *Validator) ValidJSON() error
- type View
Constants ¶
const ( // DebugMode - set the framework in debug mode. DebugMode string = "debug" // ProductionMode - set the framework in production mode. ProductionMode string = "production" // TestMode - set the framework in testing mode. TestMode string = "test" )
const VERSION = "0.5.2"
VERSION of the Framework.
Variables ¶
var DefaultErrorMessages = map[string]string{
"Required": "can not be empty",
"Min": "minimum value is %d",
"MinLength": "minimum length is %d",
"Max": "maximum value is %d",
"MaxLength": "maximum length is %d",
"Exact": "required value is %d",
"ExactLength": "required length is %d",
"Alpha": "must contain a valid alpha characters",
"AlphaNumeric": "must contain a valid alpha numeric characters",
"Numeric": "must be a valid numeric value",
"Float": "must be a valid float value",
"URL": "must be a valid URL",
"Email": "must be a valid email address",
"IP": "must be a valid ip address",
"Base64": "must be a valid base64",
"String": "must be a string",
"Float64": "must be a float64",
"Bool": "must be a bool",
}
DefaultErrorMessages contains the rule's default error messages.
Functions ¶
func ConcatenateCSS ¶
ConcatenateCSS returns concatenated CSS paths to []byte
func DecodeCookie ¶
func DecodeCookie(key []byte, maxlifetime int, signedValue string, req *http.Request) (string, error)
DecodeCookie decrypt and return the cookie id.
func EncodeCookie ¶
EncodeCookie return a new encrypted cookie string.
func GetSessionID ¶
GetSessionID return the cookie from http request.
func GetTemplateFuncs ¶
GetTemplateFuncs returs the FuncMap with framework custom functions.
func MinifyHTML ¶
MinifyHTML returns a minified HTML version. Removes all HTML comments. Remove all leading and trailing white space of each line. Pad a single space to the line if its length > 0
func RegisterController ¶
func RegisterController(c Controller)
RegisterController register the specified controller on framework. controller func Init is called on framework initialization.
func RegisterGRPCService ¶
func RegisterGRPCService(s GRPCServices)
RegisterGRPCService registers a new gRPC service. Registered services are called via Init(s *framework.GRPCServer) where you finally register your protos servers before Serving the gRPC.
func RemoveCSSComments ¶
RemoveCSSComments returns a CSS comments striped string
func RemoveHTMLComments ¶
RemoveHTMLComments removes the HTML comments from provided []byte, returns a []byte
func ServerStreamInterceptor ¶
func ServerStreamInterceptor() grpc.StreamServerInterceptor
ServerStreamInterceptor creates a single stream interceptor from a list of interceptors. Use UseGRPCStreamInterceptor to add a new global stream interceptor.
func ServerUnaryInterceptor ¶
func ServerUnaryInterceptor() grpc.UnaryServerInterceptor
ServerUnaryInterceptor creates a single unary interceptor from a list of interceptors. Use UseGRPCUnaryInterceptor to add a new global unary interceptor.
func SetGoogleAnalytics ¶
func SetGoogleAnalytics(code string)
SetGoogleAnalytics sets the google analytics id (UA-XXXXXXX-X) you can get the analytics code on views: {{ template "google_analytics" . }}
func Use ¶
func Use(filter HandlerFunc)
Use appends a new global middleware. Global middlewares are called on each request (including static files)
func UseGRPCStreamInterceptor ¶
func UseGRPCStreamInterceptor(filter grpc.StreamServerInterceptor)
UseGRPCStreamInterceptor appends a new global gRPC stream interceptor.
func UseGRPCUnaryInterceptor ¶
func UseGRPCUnaryInterceptor(filter grpc.UnaryServerInterceptor)
UseGRPCUnaryInterceptor appends a new global gRPC unary interceptor.
Types ¶
type BaseController ¶
type BaseController struct { Router Router Layout string Meta map[string]string Response http.ResponseWriter Request *http.Request }
BaseController implements the Controller. All user defined controllers must use BaseController.
func (*BaseController) Any ¶
func (c *BaseController) Any(pattern string, handlers ...HandlerFunc)
Any register a route that matches all HTTP methods. (GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD)
func (*BaseController) DELETE ¶
func (c *BaseController) DELETE(pattern string, handlers ...HandlerFunc)
DELETE is an alias to Add(pattern, "DELETE", handlers)
func (*BaseController) GET ¶
func (c *BaseController) GET(pattern string, handlers ...HandlerFunc)
GET is an alias to Add(pattern, "GET", handlers)
func (*BaseController) HEAD ¶
func (c *BaseController) HEAD(pattern string, handlers ...HandlerFunc)
HEAD is an alias to Add(pattern, "HEAD", handlers)
func (*BaseController) OPTIONS ¶
func (c *BaseController) OPTIONS(pattern string, handlers ...HandlerFunc)
OPTIONS is an alias to Add(pattern, "OPTIONS", handlers)
func (*BaseController) PATCH ¶
func (c *BaseController) PATCH(pattern string, handlers ...HandlerFunc)
PATCH is an alias to Add(pattern, "PATCH", handlers)
func (*BaseController) POST ¶
func (c *BaseController) POST(pattern string, handlers ...HandlerFunc)
POST is an alias to Add(pattern, "POST", handlers)
func (*BaseController) PUT ¶
func (c *BaseController) PUT(pattern string, handlers ...HandlerFunc)
PUT is an alias to Add(pattern, "PUT", handlers)
func (*BaseController) Route ¶
func (c *BaseController) Route(pattern string, method string, handler HandlerFunc)
Route define a route for the current controller. usage:
default methods is the same name as method Route("/user", "GET", UserController.Get) Route("/api/list", "GET", ApiController.List) Route("/api/create", "POST", ApiController.Save) Route("/api/update", "PUT", ApiController.Save) Route("/api/delete", "DELETE", ApiController.Delete)
type BeforeFunc ¶
type BeforeFunc func(ResponseWriter)
BeforeFunc defines a function called before the end of response.
type ConfigData ¶
type ConfigData struct {
// contains filtered or unexported fields
}
ConfigData contains the configuration data
func DefaultConfig ¶
func DefaultConfig() *ConfigData
DefaultConfig initialize the Config with basic configuration settings.
func (*ConfigData) Bool ¶
func (c *ConfigData) Bool(key string) bool
Bool returns the config's value by specified key, cast to bool if possible. If data type don't match, return false
func (*ConfigData) Get ¶
func (c *ConfigData) Get(key string) interface{}
Get return config's value by specified key.
func (*ConfigData) Int ¶
func (c *ConfigData) Int(key string) int
Int returns the config's value by specified key, cast to int if possible. If data type don't match, return 0
func (*ConfigData) Set ¶
func (c *ConfigData) Set(key string, value interface{})
Set updates a key with value.
func (*ConfigData) String ¶
func (c *ConfigData) String(key string) string
String returns the config's value by specified key, cast to string if possible. If data type don't match, return an empty string
type Configuration ¶
type Configuration interface { Set(key string, value interface{}) Get(key string) interface{} String(key string) string Int(key string) int Bool(key string) bool }
Configuration is the interface for app configuration.
var Config Configuration
Config is the framework global configuration
func LoadConfig ¶
func LoadConfig(path string) Configuration
LoadConfig loads the configuration file from specified path and returns the Config object.
type Context ¶
type Context struct { Request *Request Response ResponseWriter Router *Router Params map[string]string Session Session I18n *i18n.I18N Data map[string]interface{} // contains filtered or unexported fields }
Context wraps Request and Response. It also provides methods for handling responses.
func NewContext ¶
func NewContext(w ResponseWriter, r *Request) *Context
NewContext creates new context for the given w and r.
func (*Context) ParseForm ¶
ParseForm detects the post Content-Type and prepares the form fields. If the Content-Type is application/json the values are decoded into the request JSON and JSONRaw params.
func (*Context) WriteFlash ¶
WriteFlash store the flash data into the current session.
type ContextPool ¶
type ContextPool struct {
// contains filtered or unexported fields
}
ContextPool contains the framework Context pool.
func (*ContextPool) Get ¶
func (cp *ContextPool) Get(rw ResponseWriter, req *Request) (c *Context)
Get a context from the pool.
type Controller ¶
type Controller interface { Route(pattern string, method string, handler HandlerFunc) GET(pattern string, handlers ...HandlerFunc) POST(pattern string, handlers ...HandlerFunc) PUT(pattern string, handlers ...HandlerFunc) DELETE(pattern string, handlers ...HandlerFunc) PATCH(pattern string, handlers ...HandlerFunc) OPTIONS(pattern string, handlers ...HandlerFunc) HEAD(pattern string, handlers ...HandlerFunc) Any(pattern string, handlers ...HandlerFunc) }
Controller interface for controller.
type Email ¶
type Email struct {
// contains filtered or unexported fields
}
Email struct contains the email parameters.
func (*Email) Bcc ¶
Bcc sets a list of blind carbon copy (BCC) addresses.
You can pass single or multiple addresses to this method.
mail.Bcc("first@email.com", "second@email.com")
func (*Email) ClearAttachments ¶
func (m *Email) ClearAttachments()
ClearAttachments removes all attachments.
type Emailer ¶
type Emailer interface { From(email string) FromName(name string) ReplyTo(email string) To(emails ...string) Bcc(emails ...string) Subject(subject string) Send() error HTML() *BodyPart Plain() *BodyPart }
Emailer is the interface for email sending.
type Engine ¶
type Engine struct { Controllers []Controller Router Router View Renderer GRPCServer *GRPCServer Path string // contains filtered or unexported fields }
Engine is the framework struct.
var App *Engine
App contains a pointer to the framework instance. It's initialized automatically when application starts. To start HTTP listening use framework.Run()
type FileSessionProvider ¶
FileSessionProvider contains the cookie store.
func (*FileSessionProvider) Delete ¶
func (fsp *FileSessionProvider) Delete(key string) error
Delete value in cookie session.
func (*FileSessionProvider) Destroy ¶
func (fsp *FileSessionProvider) Destroy() error
Destroy entire session
func (*FileSessionProvider) Get ¶
func (fsp *FileSessionProvider) Get(key string) interface{}
Get value from cookie session.
func (*FileSessionProvider) Init ¶
func (fsp *FileSessionProvider) Init(rw http.ResponseWriter, r *http.Request) (Session, error)
Init checks if session id exists and return it.
func (*FileSessionProvider) Release ¶
func (fsp *FileSessionProvider) Release(rw http.ResponseWriter, req *http.Request)
Release writes the cookie back to the http response cookie
func (*FileSessionProvider) SessionID ¶
func (fsp *FileSessionProvider) SessionID() string
SessionID Return id of this cookie session
func (*FileSessionProvider) Set ¶
func (fsp *FileSessionProvider) Set(key string, value interface{}) error
Set value to cookie session.
type GRPCServer ¶
GRPCServer is the structure that contains the gRPC server.
func NewGRPC ¶
func NewGRPC(opt ...grpc.ServerOption) *GRPCServer
NewGRPC instantiates a new gRPC server.
type GRPCService ¶
type GRPCService struct{}
GRPCService implements the gRPC Service. All user defined services must use this structure.
type GRPCServices ¶
type GRPCServices interface{}
GRPCServices is the gRPC interface used for service registration.
type HandlerFunc ¶
type HandlerFunc func(c *Context)
HandlerFunc defines the function type for controller requests.
type JSONData ¶
type JSONData struct { JSONValue // contains filtered or unexported fields }
JSONData contains the array map to values.
func PrepareJSON ¶
PrepareJSON instantiate the JSONData and unmarshal the data json, returns a JSONData struct.
func (*JSONData) PrepareInterface ¶
PrepareInterface is a recursive function to translate json objects to maps.
type JSONValue ¶
type JSONValue struct {
// contains filtered or unexported fields
}
JSONValue contains values from JSONData.
func (*JSONValue) Array ¶
func (v *JSONValue) Array() []interface{}
Array returns the values as an array.
type Logger ¶
Logger is the logger structure
var Log *Logger
Log is the framework global Logger
type Renderer ¶
type Renderer interface { Render(out io.Writer, name string, data interface{}) error Parse(name string, data []byte) error }
Renderer is the interface for template rendering.
type Request ¶
type Request struct { *http.Request JSON *JSONData // JsonRaw contains the raw json message. JSONRaw string }
Request extends the default http.Request.
type ResponseWriter ¶
type ResponseWriter interface { http.ResponseWriter http.Hijacker // Before calls a function before the ResponseWriter has been written. Before(BeforeFunc) Status() int }
ResponseWriter extends http.ResponseWriter.
func NewResponseWriter ¶
func NewResponseWriter(rw http.ResponseWriter) ResponseWriter
NewResponseWriter creates a ResponseWriter that wraps an http.ResponseWriter
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route contain the single route structure
type Router ¶
type Router interface { Add(pattern string, method string, handlers ...HandlerFunc) ServeHTTP(rw http.ResponseWriter, req *http.Request) }
Router is the framework router interface
type Routes ¶
type Routes struct {
// contains filtered or unexported fields
}
Routes contains the framework routes, middleware and custom http error messages
func (*Routes) Add ¶
func (r *Routes) Add(pattern string, method string, handlers ...HandlerFunc)
Add adds a new route to the app routes.
func (*Routes) OnError ¶
func (r *Routes) OnError(code int, handlerFunc HandlerFunc)
OnError add a custom error handler
func (*Routes) ServeHTTP ¶
func (r *Routes) ServeHTTP(rw http.ResponseWriter, req *http.Request)
ServeHTTP handle the request based on defined routes.
func (*Routes) ServeStaticFiles ¶
ServeStaticFiles check if requested path is a static file and serve the content.
type Session ¶
type Session interface { // Init checks if session id exists and return it. // if session does not exists, creates a new one. Init(http.ResponseWriter, *http.Request) (Session, error) // Release writes back the session header Release(http.ResponseWriter, *http.Request) // Set sets value to given key in session. Set(key string, value interface{}) error // Get gets value by given key in session. Get(string) interface{} // Delete deletes a key from session. Delete(string) error // Destroy the entire session Destroy() error // SessionID returns current session ID. SessionID() string // Handle Handler(c *Context) }
Session contains the base session provider. Load configuration automatically from app.json file
func NewFileSessionProvider ¶
NewFileSessionProvider returns a new file session provider.
func NewSession ¶
func NewSession(name string, config string, provider SessionProvider) (Session, error)
NewSession creates the session provider instance using the provided name as provider and add it to the available session providers.
type SessionConfig ¶
type SessionConfig struct { // Name is the cookie session name Name string `json:"name"` // // // Config string `json:"config"` // Domain limits cookie access to specified domain Domain string `json:"domain"` // MaxLifetime as seconds MaxLifetime int `json:"max_lifetime"` // Key is a private key used to encrypt session cookies Key string `json:"key"` // HTTPOnly allow access to cookies only via HTTP requests, // Set to true to protect against XSS exploits HTTPOnly bool `json:"http_only"` }
SessionConfig contains the session instance default configuration.
type SessionProvider ¶
SessionProvider contains the session instance.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator contains the methods for error checking. Values are retreived automatically from Context.
func NewValidator ¶
NewValidator returns a new Validator instance
func (*Validator) AlphaNumeric ¶
AlphaNumeric check if value contains only alphanumeric values
func (*Validator) ExactLength ¶
ExactLength check if value length is equal to length
func (*Validator) Rule ¶
Rule adds a new rule to based on field. If the rule needs to pass parameters (f.e. MaxLength of 100) put the value into brackets: MaxLength[100]
func (*Validator) Valid ¶
Valid check if all rules are valid from provided map[string]string, otherwise return the rule error message.
type View ¶
View implements the Renderer interface.
func (*View) EmbedShortcodes ¶
func (s *View) EmbedShortcodes()
EmbedShortcodes defines the views shortcodes.
func (*View) EmbedTemplates ¶
func (s *View) EmbedTemplates()
EmbedTemplates defines the views templates (e.g. google analytics).