Documentation ¶
Overview ¶
Package aah is A scalable, performant, rapid development Web framework for Go https://aahframework.org
Index ¶
- Constants
- Variables
- func ActionMiddleware(ctx *Context, m *Middleware)
- func AddController(c interface{}, methods []*MethodInfo)
- func AddLoggerHook(name string, hook log.HookFunc) error
- func AddPasswordAlgorithm(name string, encoder acrypto.PasswordEncoder) error
- func AddServerTLSConfig(tlsCfg *tls.Config)
- func AddSessionStore(name string, store session.Storer) error
- func AddTemplateFunc(funcs template.FuncMap)
- func AddValueParser(typ reflect.Type, parser valpar.Parser) error
- func AddViewEngine(name string, engine view.Enginer) error
- func AllAppProfiles() []string
- func AntiCSRFMiddleware(ctx *Context, m *Middleware)
- func AppBaseDir() string
- func AppConfig() *config.Config
- func AppDefaultI18nLang() string
- func AppDesc() string
- func AppHTTPAddress() string
- func AppHTTPPort() string
- func AppI18n() *i18n.I18n
- func AppI18nLocales() []string
- func AppImportPath() string
- func AppInstanceName() string
- func AppIsSSLEnabled() bool
- func AppName() string
- func AppProfile() string
- func AppRouter() *router.Router
- func AppSecurityManager() *security.Manager
- func AppSessionManager() *session.Manager
- func AppViewEngine() view.Enginer
- func AuthcAuthzMiddleware(ctx *Context, m *Middleware)
- func BindMiddleware(ctx *Context, m *Middleware)
- func CORSMiddleware(ctx *Context, m *Middleware)
- func Init(importPath string)
- func Middlewares(middlewares ...MiddlewareFunc)
- func NewChildLogger(ctx log.Fields) *log.Logger
- func OnAfterReply(sef EventCallbackFunc)
- func OnInit(ecb EventCallbackFunc, priority ...int)
- func OnPostAuth(sef EventCallbackFunc)
- func OnPreAuth(sef EventCallbackFunc)
- func OnPreReply(sef EventCallbackFunc)
- func OnRequest(sef EventCallbackFunc)
- func OnShutdown(ecb EventCallbackFunc, priority ...int)
- func OnStart(ecb EventCallbackFunc, priority ...int)
- func PublishEvent(eventName string, data interface{})
- func PublishEventSync(eventName string, data interface{})
- func RouteMiddleware(ctx *Context, m *Middleware)
- func SetAppBuildInfo(bi *BuildInfo)
- func SetAppPackaged(pack bool)
- func SetAppProfile(profile string) error
- func SetErrorHandler(handlerFunc ErrorHandlerFunc)
- func SetMinifier(fn MinifierFunc)
- func SetTLSConfig(tlsCfg *tls.Config)
- func Shutdown()
- func Start()
- func SubscribeEvent(eventName string, ec EventCallback)
- func SubscribeEventf(eventName string, ecf EventCallbackFunc)
- func UnsubscribeEvent(eventName string, ec EventCallback)
- func UnsubscribeEventf(eventName string, ecf EventCallbackFunc)
- func Validate(s interface{}) (validator.ValidationErrors, error)
- func ValidateValue(v interface{}, rules string) bool
- func Validator() *validator.Validate
- type Binary
- type BuildInfo
- type Context
- func (ctx *Context) Abort()
- func (ctx *Context) AddViewArg(key string, value interface{}) *Context
- func (ctx *Context) Get(key string) interface{}
- func (ctx *Context) IsStaticRoute() bool
- func (ctx *Context) Log() log.Loggerer
- func (ctx *Context) Msg(key string, args ...interface{}) string
- func (ctx *Context) Msgl(locale *ahttp.Locale, key string, args ...interface{}) string
- func (ctx *Context) Reply() *Reply
- func (ctx *Context) Reset()
- func (ctx *Context) ReverseURL(routeName string, args ...interface{}) string
- func (ctx *Context) ReverseURLm(routeName string, args map[string]interface{}) string
- func (ctx *Context) Session() *session.Session
- func (ctx *Context) Set(key string, value interface{})
- func (ctx *Context) SetMethod(method string)
- func (ctx *Context) SetURL(pathURL string)
- func (ctx *Context) Subdomain() string
- func (ctx *Context) Subject() *security.Subject
- func (ctx *Context) ViewArgs() map[string]interface{}
- type Data
- type Error
- type ErrorHandler
- type ErrorHandlerFunc
- type Event
- type EventCallback
- type EventCallbackFunc
- type EventCallbacks
- type EventStore
- func (es *EventStore) IsEventExists(eventName string) bool
- func (es *EventStore) Publish(e *Event)
- func (es *EventStore) PublishSync(e *Event)
- func (es *EventStore) Subscribe(event string, ec EventCallback)
- func (es *EventStore) SubscriberCount(eventName string) int
- func (es *EventStore) Unsubscribe(event string, callback EventCallbackFunc)
- type HTML
- type JSON
- type MethodInfo
- type Middleware
- type MiddlewareFunc
- type MinifierFunc
- type ParameterInfo
- type Render
- type RenderFunc
- type Reply
- func (r *Reply) Accepted() *Reply
- func (r *Reply) BadRequest() *Reply
- func (r *Reply) Binary(b []byte) *Reply
- func (r *Reply) Body() *bytes.Buffer
- func (r *Reply) Conflict() *Reply
- func (r *Reply) ContentType(contentType string) *Reply
- func (r *Reply) Cookie(cookie *http.Cookie) *Reply
- func (r *Reply) Created() *Reply
- func (r *Reply) DisableGzip() *Reply
- func (r *Reply) Done() *Reply
- func (r *Reply) Error(err *Error) *Reply
- func (r *Reply) File(file string) *Reply
- func (r *Reply) FileDownload(file, targetName string) *Reply
- func (r *Reply) FileInline(file, targetName string) *Reply
- func (r *Reply) Forbidden() *Reply
- func (r *Reply) Found() *Reply
- func (r *Reply) HTML(data Data) *Reply
- func (r *Reply) HTMLf(filename string, data Data) *Reply
- func (r *Reply) HTMLl(layout string, data Data) *Reply
- func (r *Reply) HTMLlf(layout, filename string, data Data) *Reply
- func (r *Reply) Header(key, value string) *Reply
- func (r *Reply) HeaderAppend(key, value string) *Reply
- func (r *Reply) InternalServerError() *Reply
- func (r *Reply) IsContentTypeSet() bool
- func (r *Reply) JSON(data interface{}) *Reply
- func (r *Reply) JSONP(data interface{}, callback string) *Reply
- func (r *Reply) MethodNotAllowed() *Reply
- func (r *Reply) MovedPermanently() *Reply
- func (r *Reply) NoContent() *Reply
- func (r *Reply) NotFound() *Reply
- func (r *Reply) Ok() *Reply
- func (r *Reply) Readfrom(reader io.Reader) *Reply
- func (r *Reply) Redirect(redirectURL string) *Reply
- func (r *Reply) RedirectSts(redirectURL string, code int) *Reply
- func (r *Reply) Render(rdr Render) *Reply
- func (r *Reply) Reset()
- func (r *Reply) ServiceUnavailable() *Reply
- func (r *Reply) Status(code int) *Reply
- func (r *Reply) TemporaryRedirect() *Reply
- func (r *Reply) Text(format string, values ...interface{}) *Reply
- func (r *Reply) Unauthorized() *Reply
- func (r *Reply) XML(data interface{}) *Reply
- type Text
- type XML
Constants ¶
const ( // EventOnInit event is fired right after aah application config is initialized. EventOnInit = "OnInit" // EventOnStart event is fired before HTTP/Unix listener starts EventOnStart = "OnStart" // EventOnShutdown event is fired when server recevies an interrupt or kill command. EventOnShutdown = "OnShutdown" // EventOnRequest event is fired when server recevies an incoming request. EventOnRequest = "OnRequest" // EventOnPreReply event is fired when before server writes the reply on the wire. // Except when // 1) `Reply().Done()`, // 2) `Reply().Redirect(...)` is called. // Refer `aah.Reply.Done()` godoc for more info. EventOnPreReply = "OnPreReply" // EventOnAfterReply event is fired when before server writes the reply on the wire. // Except when // 1) `Reply().Done()`, // 2) `Reply().Redirect(...)` is called. // Refer `aah.Reply.Done()` godoc for more info. EventOnAfterReply = "OnAfterReply" // EventOnPreAuth event is fired before server Authenticates & Authorizes an incoming request. EventOnPreAuth = "OnPreAuth" // EventOnPostAuth event is fired after server Authenticates & Authorizes an incoming request. EventOnPostAuth = "OnPostAuth" )
const ( // KeyViewArgAuthcInfo key name is used to store `AuthenticationInfo` instance into `ViewArgs`. KeyViewArgAuthcInfo = "_aahAuthcInfo" // KeyViewArgSubject key name is used to store `Subject` instance into `ViewArgs`. KeyViewArgSubject = "_aahSubject" )
const ( // KeyViewArgRequestParams key name is used to store HTTP Request Params instance // into `ViewArgs`. KeyViewArgRequestParams = "_aahRequestParams" )
const Version = "0.10"
Version no. of aah framework
Variables ¶
var ( ErrPanicRecovery = errors.New("aah: panic recovery") ErrDomainNotFound = errors.New("aah: domain not found") ErrRouteNotFound = errors.New("aah: route not found") ErrStaticFileNotFound = errors.New("aah: static file not found") ErrControllerOrActionNotFound = errors.New("aah: controller or action not found") ErrInvalidRequestParameter = errors.New("aah: invalid request parameter") ErrContentTypeNotAccepted = errors.New("aah: content type not accepted") ErrContentTypeNotOffered = errors.New("aah: content type not offered") ErrHTTPMethodNotAllowed = errors.New("aah: http method not allowed") ErrAccessDenied = errors.New("aah: access denied") ErrAuthenticationFailed = errors.New("aah: authentication failed") ErrGeneric = errors.New("aah: generic error") ErrValidation = errors.New("aah: validation error") )
aah errors
var ( // JSONMarshal is used to register external JSON library for Marshalling. JSONMarshal func(v interface{}) ([]byte, error) // JSONMarshalIndent is used to register external JSON library for Marshal indent. JSONMarshalIndent func(v interface{}, prefix, indent string) ([]byte, error) )
Functions ¶
func ActionMiddleware ¶ added in v0.10.1
func ActionMiddleware(ctx *Context, m *Middleware)
ActionMiddleware performs
- Executes Interceptors (Before, Before<ActionName>, After, After<ActionName>, Panic, Panic<ActionName>, Finally, Finally<ActionName>)
- Invokes Controller Action
func AddController ¶
func AddController(c interface{}, methods []*MethodInfo)
AddController method adds given controller into controller registory. with "dereferenced" a.k.a "indirecting".
func AddLoggerHook ¶ added in v0.10.1
AddLoggerHook method adds given logger into aah application default logger.
func AddPasswordAlgorithm ¶ added in v0.10.1
func AddPasswordAlgorithm(name string, encoder acrypto.PasswordEncoder) error
AddPasswordAlgorithm method adds given password algorithm to encoders list. Implementation have to implement interface `PasswordEncoder`.
/ Then you can use it `security.auth_schemes.*`.
func AddServerTLSConfig ¶ added in v0.5.1
AddServerTLSConfig method can be used for custom TLS config for aah server.
DEPRECATED: Use method `aah.SetTLSConfig` instead. Planned to be removed in `v1.0` release.
func AddSessionStore ¶
AddSessionStore method allows you to add custom session store which implements `session.Storer` interface. The `name` parameter is used in aah.conf on `session.store.type = "name"`.
func AddTemplateFunc ¶
AddTemplateFunc method adds template func map into view engine.
func AddValueParser ¶ added in v0.10.1
AddValueParser method adds given custom value parser for the `reflect.Type`
func AddViewEngine ¶
AddViewEngine method adds the given name and view engine to view store.
func AllAppProfiles ¶
func AllAppProfiles() []string
AllAppProfiles method returns all the aah application environment profile names.
func AntiCSRFMiddleware ¶ added in v0.10.1
func AntiCSRFMiddleware(ctx *Context, m *Middleware)
func AppBaseDir ¶
func AppBaseDir() string
AppBaseDir method returns the application base or binary current directory
For e.g.: $GOPATH/src/github.com/user/myproject <app/binary/path/base/directory>
func AppConfig ¶
func AppConfig() *config.Config
AppConfig method returns aah application configuration instance.
func AppDefaultI18nLang ¶
func AppDefaultI18nLang() string
AppDefaultI18nLang method returns aah application i18n default language if configured other framework defaults to "en".
func AppDesc ¶ added in v0.5.1
func AppDesc() string
AppDesc method returns aah application friendly description from app config otherwise empty string.
func AppHTTPAddress ¶
func AppHTTPAddress() string
AppHTTPAddress method returns aah application HTTP address otherwise empty string
func AppHTTPPort ¶
func AppHTTPPort() string
AppHTTPPort method returns aah application HTTP port number based on `server.port` value. Possible outcomes are user-defined port, `80`, `443` and `8080`.
func AppI18n ¶
func AppI18n() *i18n.I18n
AppI18n method returns aah application I18n store instance.
func AppI18nLocales ¶
func AppI18nLocales() []string
AppI18nLocales returns all the loaded locales from i18n store
func AppImportPath ¶
func AppImportPath() string
AppImportPath method returns the application Go import path.
func AppInstanceName ¶ added in v0.10.1
func AppInstanceName() string
AppInstanceName method returns aah application instane name from app config `instance_name` otherwise empty string.
func AppIsSSLEnabled ¶
func AppIsSSLEnabled() bool
AppIsSSLEnabled method returns true if aah application is enabled with SSL otherwise false.
func AppName ¶
func AppName() string
AppName method returns aah application name from app config `name` otherwise app name of the base directory.
func AppProfile ¶
func AppProfile() string
AppProfile returns aah application configuration profile name For e.g.: dev, prod, etc. Default is `dev`
func AppRouter ¶
func AppRouter() *router.Router
AppRouter method returns aah application router instance.
func AppSecurityManager ¶ added in v0.10.1
func AppSecurityManager() *security.Manager
AppSecurityManager method returns the application security instance, which manages the Session, CORS, CSRF, Security Headers, etc.
func AppSessionManager ¶
AppSessionManager method returns the application session manager. By default session is stateless.
func AppViewEngine ¶
func AppViewEngine() view.Enginer
AppViewEngine method returns aah application view Engine instance.
func AuthcAuthzMiddleware ¶ added in v0.10.1
func AuthcAuthzMiddleware(ctx *Context, m *Middleware)
AuthcAuthzMiddleware is aah Authentication and Authorization Middleware.
func BindMiddleware ¶ added in v0.10.1
func BindMiddleware(ctx *Context, m *Middleware)
BindMiddleware method parses the incoming HTTP request to collects request parameters (Path, Form, Query, Multipart) stores into context. Request params are made available in View via template functions.
func CORSMiddleware ¶ added in v0.10.1
func CORSMiddleware(ctx *Context, m *Middleware)
func Init ¶
func Init(importPath string)
Init method initializes `aah` application, if anything goes wrong during initialize process, it will log it as fatal msg and exit.
func Middlewares ¶
func Middlewares(middlewares ...MiddlewareFunc)
Middlewares method adds given middleware into middleware stack
func NewChildLogger ¶ added in v0.10.1
func NewChildLogger(ctx log.Fields) *log.Logger
NewChildLogger method create a child logger from aah application default logger.
func OnAfterReply ¶
func OnAfterReply(sef EventCallbackFunc)
OnAfterReply method is to subscribe to aah server `OnAfterReply` extension point. `OnAfterReply` called for every reply from aah server.
Except when
- `Reply().Done()`,
- `Reply().Redirect(...)` is called.
Refer `aah.Reply.Done()` godoc for more info.
func OnInit ¶
func OnInit(ecb EventCallbackFunc, priority ...int)
OnInit method is to subscribe to aah application `OnInit` event. `OnInit` event published right after the aah application configuration `aah.conf` initialized.
func OnPostAuth ¶ added in v0.10.1
func OnPostAuth(sef EventCallbackFunc)
OnPostAuth method is to subscribe to aah application `OnPreAuth` event. `OnPostAuth` event pubished right after the aah server is authenticates & authorizes an incoming request.
func OnPreAuth ¶ added in v0.10.1
func OnPreAuth(sef EventCallbackFunc)
OnPreAuth method is to subscribe to aah application `OnPreAuth` event. `OnPreAuth` event pubished right before the aah server is authenticates & authorizes an incoming request.
func OnPreReply ¶
func OnPreReply(sef EventCallbackFunc)
OnPreReply method is to subscribe to aah server `OnPreReply` extension point. `OnPreReply` called for every reply from aah server.
Except when
- `Reply().Done()`,
- `Reply().Redirect(...)` is called.
Refer `aah.Reply.Done()` godoc for more info.
func OnRequest ¶
func OnRequest(sef EventCallbackFunc)
OnRequest method is to subscribe to aah server `OnRequest` extension point. `OnRequest` called for every incoming request.
The `aah.Context` object passed to the extension functions is decorated with the `ctx.SetURL()` and `ctx.SetMethod()` methods. Calls to these methods will impact how the request is routed and can be used for rewrite rules.
Route is not yet populated/evaluated at this point.
func OnShutdown ¶
func OnShutdown(ecb EventCallbackFunc, priority ...int)
OnShutdown method is to subscribe to aah application `OnShutdown` event. `OnShutdown` event pubished right before the aah server is stopped Listening and serving request.
func OnStart ¶
func OnStart(ecb EventCallbackFunc, priority ...int)
OnStart method is to subscribe to aah application `OnStart` event. `OnStart` event pubished right before the aah server listen and serving request.
func PublishEvent ¶
func PublishEvent(eventName string, data interface{})
PublishEvent method publishes events to subscribed callbacks asynchronously. It means each subscribed callback executed via goroutine.
func PublishEventSync ¶
func PublishEventSync(eventName string, data interface{})
PublishEventSync method publishes events to subscribed callbacks synchronously.
func RouteMiddleware ¶ added in v0.10.1
func RouteMiddleware(ctx *Context, m *Middleware)
RouteMiddleware method performs the routing logic.
func SetAppBuildInfo ¶
func SetAppBuildInfo(bi *BuildInfo)
SetAppBuildInfo method sets the user application build info into aah instance.
func SetAppPackaged ¶ added in v0.5.1
func SetAppPackaged(pack bool)
SetAppPackaged method sets the info of binary is packaged or not.
func SetAppProfile ¶
SetAppProfile method sets given profile as current aah application profile.
For Example: aah.SetAppProfile("prod")
func SetErrorHandler ¶ added in v0.10.1
func SetErrorHandler(handlerFunc ErrorHandlerFunc)
SetErrorHandler method is used to register centralized application error handling. If custom handler is not then default error handler is used.
func SetMinifier ¶ added in v0.10.1
func SetMinifier(fn MinifierFunc)
SetMinifier method sets the given minifier func into aah framework. Note: currently minifier is called only for HTML contentType.
func SetTLSConfig ¶ added in v0.10.1
SetTLSConfig method is used to set custom TLS config for aah server. Note: if `server.ssl.lets_encrypt.enable=true` then framework sets the `GetCertificate` from autocert manager.
Use `aah.OnInit` or `func init() {...}` to assign your custom TLS Config.
func Shutdown ¶
func Shutdown()
Shutdown method allows aah server to shutdown gracefully with given timeoout in seconds. It's invoked on OS signal `SIGINT` and `SIGTERM`.
Method performs:
- Graceful server shutdown with timeout by `server.timeout.grace_shutdown`
- Publishes `OnShutdown` event
- Exits program with code 0
func SubscribeEvent ¶
func SubscribeEvent(eventName string, ec EventCallback)
SubscribeEvent method is to subscribe to new or existing event.
func SubscribeEventf ¶ added in v0.5.1
func SubscribeEventf(eventName string, ecf EventCallbackFunc)
SubscribeEventf method is to subscribe to new or existing event by `EventCallbackFunc`.
func UnsubscribeEvent ¶
func UnsubscribeEvent(eventName string, ec EventCallback)
UnsubscribeEvent method is to unsubscribe by event name and `EventCallback` from app event store.
func UnsubscribeEventf ¶
func UnsubscribeEventf(eventName string, ecf EventCallbackFunc)
UnsubscribeEventf method is to unsubscribe by event name and `EventCallbackFunc` from app event store.
func Validate ¶ added in v0.10.1
func Validate(s interface{}) (validator.ValidationErrors, error)
Validate method is to validate struct via underneath validator.
Returns:
For validation errors: returns `validator.ValidationErrors` and nil
For invalid input: returns nil, error (invalid input such as nil, non-struct, etc.)
For no validation errors: nil, nil
func ValidateValue ¶ added in v0.10.1
ValidateValue method is to validate individual value on demand.
Returns -
true: validation passed
false: validation failed
For example:
i := 15 result := valpar.ValidateValue(i, "gt=1,lt=10") emailAddress := "sample@sample" result := valpar.ValidateValue(emailAddress, "email") numbers := []int{23, 67, 87, 23, 90} result := valpar.ValidateValue(numbers, "unique")
func Validator ¶ added in v0.10.1
func Validator() *validator.Validate
Validator method return the default validator of aah framework.
Refer to https://godoc.org/gopkg.in/go-playground/validator.v9 for detailed documentation.
Types ¶
type Binary ¶ added in v0.5.1
Binary renders given path or io.Reader into response and closes the file.
type BuildInfo ¶
BuildInfo holds the aah application build information; such as BinaryName, Version and Date.
func AppBuildInfo ¶
func AppBuildInfo() *BuildInfo
AppBuildInfo method return user application version no.
type Context ¶
type Context struct { // Req is HTTP request instance Req *ahttp.Request // Res is HTTP response writer compliant. It is highly recommended to use // `Reply()` builder for composing response. // // Note: If you're using `cxt.Res` directly, don't forget to call // `Reply().Done()` so that framework will not intervene with your // response. Res ahttp.ResponseWriter // contains filtered or unexported fields }
Context type for aah framework, gets embedded in application controller.
Note: this is not standard package `context.Context`.
func (*Context) Abort ¶
func (ctx *Context) Abort()
Abort method sets the abort to true. It means framework will not proceed with next middleware, next interceptor or action based on context it being used. Contexts:
- If it's called in the middleware, then middleware chain stops;
framework starts processing response.
- If it's called in Before interceptor then Before<Action> interceptor,
mapped <Action>, After<Action> interceptor and After interceptor will not execute; framework starts processing response.
- If it's called in Mapped <Action> then After<Action> interceptor and
After interceptor will not execute; framework starts processing response.
func (*Context) AddViewArg ¶
AddViewArg method adds given key and value into `viewArgs`. These view args values accessible on templates. Chained call is possible.
func (*Context) Get ¶ added in v0.10.1
Get method returns the value for the given key, otherwise it returns nil.
func (*Context) IsStaticRoute ¶ added in v0.5.1
IsStaticRoute method returns true if it's static route otherwise false.
func (*Context) Log ¶ added in v0.10.1
func (ctx *Context) Log() log.Loggerer
Log method addeds `Request ID`, `Primary Principal` into current log entry.
func (*Context) Msg ¶
Msg method returns the i18n value for given key otherwise empty string returned.
func (*Context) Msgl ¶
Msgl method returns the i18n value for given local and key otherwise empty string returned.
func (*Context) Reply ¶
Reply method gives you control and convenient way to write a response effectively.
func (*Context) ReverseURL ¶
ReverseURL method returns the URL for given route name and args. See `Domain.ReverseURL` for more information.
func (*Context) ReverseURLm ¶
ReverseURLm method returns the URL for given route name and key-value paris. See `Domain.ReverseURLm` for more information.
func (*Context) Session ¶
Session method always returns `session.Session` object. Use `Session.IsNew` to identify whether sesison is newly created or restored from the request which was already created.
func (*Context) Set ¶ added in v0.10.1
Set method is used to set value for the given key in the current request flow.
func (*Context) SetMethod ¶
SetMethod method is to set the request `Method` to change the behaviour of request routing. Ideal for URL rewrting.
Note: This method only takes effect on `OnRequest` server event.
func (*Context) SetURL ¶
SetURL method is to set the request URL to change the behaviour of request routing. Ideal for URL rewrting. URL can be relative or absolute URL.
Note: This method only takes effect on `OnRequest` server event.
func (*Context) Subdomain ¶ added in v0.10.1
Subdomain method returns the subdomain from the incoming request if available as per routes.conf. Otherwise empty string.
type Data ¶
type Data map[string]interface{}
Data type used for convenient data type of map[string]interface{}
func (Data) MarshalXML ¶ added in v0.10.1
MarshalXML method is to marshal `aah.Data` into XML.
type Error ¶ added in v0.10.1
type Error struct { Reason error `json:"-" xml:"-"` Code int `json:"code,omitempty" xml:"code,omitempty"` Message string `json:"message,omitempty" xml:"message,omitempty"` Data interface{} `json:"data,omitempty" xml:"data,omitempty"` }
Error structure used to represent the error details in the aah framework.
type ErrorHandler ¶ added in v0.10.1
type ErrorHandler interface { // HandleError method is to handle error on your controller // // - Return `true`, if you have handled your errors, aah just writes the reply on the wire. // // - Return `false`, aah would propagate the error further to centralized // error handler, if not handled and then finally default error handler would take place. HandleError(err *Error) bool }
ErrorHandler is interface for implement controller level error handling
type ErrorHandlerFunc ¶ added in v0.10.1
ErrorHandlerFunc is function type, it used to define centralized error handler for your application.
Return `true`, if you have handled your errors, aah just writes the reply on the wire.
Return `false`, you may or may not handled the error, aah would propagate the error further to default
error handler.
type Event ¶
type Event struct { Name string Data interface{} }
Event type holds the details of single event.
type EventCallback ¶
type EventCallback struct { Callback EventCallbackFunc CallOnce bool // contains filtered or unexported fields }
EventCallback type is store particular callback in priority for calling sequance.
type EventCallbackFunc ¶
type EventCallbackFunc func(e *Event)
EventCallbackFunc is signature of event callback function.
type EventCallbacks ¶
type EventCallbacks []EventCallback
EventCallbacks type is slice of `EventCallback` type.
func (EventCallbacks) Less ¶
func (ec EventCallbacks) Less(i, j int) bool
func (EventCallbacks) Swap ¶
func (ec EventCallbacks) Swap(i, j int)
type EventStore ¶
type EventStore struct {
// contains filtered or unexported fields
}
EventStore type holds all the events belongs to aah application.
func AppEventStore ¶
func AppEventStore() *EventStore
AppEventStore method returns aah application event store.
func (*EventStore) IsEventExists ¶
func (es *EventStore) IsEventExists(eventName string) bool
IsEventExists method returns true if given event is exists in the event store otherwise false.
func (*EventStore) Publish ¶
func (es *EventStore) Publish(e *Event)
Publish method publishes events to subscribed callbacks asynchronously. It means each subscribed callback executed via goroutine.
func (*EventStore) PublishSync ¶
func (es *EventStore) PublishSync(e *Event)
PublishSync method publishes events to subscribed callbacks synchronously.
func (*EventStore) Subscribe ¶
func (es *EventStore) Subscribe(event string, ec EventCallback)
Subscribe method is to subscribe any event with event callback info.
func (*EventStore) SubscriberCount ¶
func (es *EventStore) SubscriberCount(eventName string) int
SubscriberCount method returns subscriber count for given event name.
func (*EventStore) Unsubscribe ¶
func (es *EventStore) Unsubscribe(event string, callback EventCallbackFunc)
Unsubscribe method is to unsubscribe any callback from event store by event.
type MethodInfo ¶
type MethodInfo struct { Name string Parameters []*ParameterInfo }
MethodInfo holds information of single method information in the controller.
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware struct is to implement aah framework middleware chain.
func (*Middleware) Next ¶
func (mw *Middleware) Next(ctx *Context)
Next method calls next middleware in the chain if available.
type MiddlewareFunc ¶
type MiddlewareFunc func(ctx *Context, m *Middleware)
MiddlewareFunc func type is aah framework middleware signature.
func ToMiddleware ¶
func ToMiddleware(handler interface{}) MiddlewareFunc
ToMiddleware method expands the possibilities. It helps Golang community to convert the third-party or your own net/http middleware into `aah.MiddlewareFunc`
You can register below handler types: 1) aah.ToMiddleware(h http.Handler) 2) aah.ToMiddleware(h http.HandlerFunc) 3) aah.ToMiddleware(func(w http.ResponseWriter, r *http.Request))
type MinifierFunc ¶ added in v0.10.1
MinifierFunc is to minify the HTML buffer and write the response into writer.
type ParameterInfo ¶
type ParameterInfo struct { Name string Type reflect.Type // contains filtered or unexported fields }
ParameterInfo holds information of single parameter in the method.
type RenderFunc ¶ added in v0.10.1
RenderFunc type is an adapter to allow the use of regular function as custom Render.
type Reply ¶
type Reply struct { Code int ContType string Hdr http.Header Rdr Render // contains filtered or unexported fields }
Reply gives you control and convenient way to write a response effectively.
func (*Reply) BadRequest ¶
BadRequest method sets the HTTP Code as 400 RFC 7231, 6.5.1.
func (*Reply) Binary ¶ added in v0.5.1
Binary method writes given bytes into response. It auto-detects the content type of the given bytes if header `Content-Type` is not set.
func (*Reply) Body ¶ added in v0.5.1
Body method returns the response body buffer. It might be nil if the -
- Response is written successfully on the wire
- Response is not yet rendered
- Static files, since response is written via `http.ServeContent`
func (*Reply) ContentType ¶
ContentType method sets given Content-Type string for the response. Also Reply instance provides easy to use method for very frequently used Content-Type(s).
By default aah framework try to determine response 'Content-Type' from 'ahttp.Request.AcceptContentType'.
func (*Reply) DisableGzip ¶ added in v0.5.1
DisableGzip method allows you disable Gzip for the reply. By default every response is gzip compressed if the client supports it and gzip enabled in app config.
func (*Reply) Done ¶
Done method indicates to framework and informing that reply has already been sent via `aah.Context.Res` and that no further action is needed. Framework doesn't intervene with response if this method called.
func (*Reply) Error ¶ added in v0.10.1
Error method is used send an error reply, which is handled by centralized error handler.
func (*Reply) File ¶
File method send the given as file to client. It auto-detects the content type of the file if `Content-Type` is not set.
func (*Reply) FileDownload ¶ added in v0.5.1
FileDownload method send the given as file to client as a download. It sets the `Content-Disposition` as `attachment` with given target name and auto-detects the content type of the file if `Content-Type` is not set.
func (*Reply) FileInline ¶
FileInline method send the given as file to client to display. For e.g.: display within the browser. It sets the `Content-Disposition` as
`inline` with given target name and auto-detects the content type of
the file if `Content-Type` is not set.
func (*Reply) HTML ¶
HTML method renders given data with auto mapped template name and layout by framework. Also it sets HTTP 'Content-Type' as 'text/html; charset=utf-8'. By default aah framework renders the template based on
path 'Namespace/Sub-package' of Controller,
path 'Controller.Action',
view extension 'view.ext' and
case sensitive 'view.case_sensitive' from aah.conf
default layout is 'master.html' E.g.: Namespace/Sub-package: frontend Controller: App Action: Login view.ext: html
template => /views/pages/frontend/app/login.html => /views/pages/frontend/App/Login.html
func (*Reply) HTMLf ¶ added in v0.5.1
HTMLf method renders based on given filename and data. Refer `Reply.HTML(...)` method.
func (*Reply) HTMLl ¶
HTMLl method renders based on given layout and data. Refer `Reply.HTML(...)` method.
func (*Reply) HTMLlf ¶
HTMLlf method renders based on given layout, filename and data. Refer `Reply.HTML(...)` method.
func (*Reply) Header ¶
Header method sets the given header and value for the response. If value == "", then this method deletes the header. Note: It overwrites existing header value if it's present.
func (*Reply) HeaderAppend ¶
HeaderAppend method appends the given header and value for the response. Note: It does not overwrite existing header, it just appends to it.
func (*Reply) InternalServerError ¶
InternalServerError method sets the HTTP Code as 500 RFC 7231, 6.6.1.
func (*Reply) IsContentTypeSet ¶
IsContentTypeSet method returns true if Content-Type is set otherwise false.
func (*Reply) JSON ¶
JSON method renders given data as JSON response. Also it sets HTTP 'Content-Type' as 'application/json; charset=utf-8'. Response rendered pretty if 'render.pretty' is true.
func (*Reply) JSONP ¶
JSONP method renders given data as JSONP response with callback. Also it sets HTTP 'Content-Type' as 'application/json; charset=utf-8'. Response rendered pretty if 'render.pretty' is true.
func (*Reply) MethodNotAllowed ¶
MethodNotAllowed method sets the HTTP Code as 405 RFC 7231, 6.5.5.
func (*Reply) MovedPermanently ¶
MovedPermanently method sets the HTTP Code as 301 RFC 7231, 6.4.2.
func (*Reply) Readfrom ¶ added in v0.5.1
Readfrom method reads the data from given reader and writes into response. It auto-detects the content type of the file if `Content-Type` is not set. Note: Method will close the reader after serving if it's satisfies the `io.Closer`.
func (*Reply) RedirectSts ¶ added in v0.5.1
RedirectSts method redirect the to given redirect URL and status code.
func (*Reply) Render ¶ added in v0.10.1
Render method is used for custom rendering by implementing interface `aah.Render`.
func (*Reply) Reset ¶ added in v0.5.1
func (r *Reply) Reset()
Reset method resets the instance values for repurpose.
func (*Reply) ServiceUnavailable ¶
ServiceUnavailable method sets the HTTP Code as 503 RFC 7231, 6.6.4.
func (*Reply) Status ¶
Status method sets the HTTP Code code for the response. Also Reply instance provides easy to use method for very frequently used HTTP Status Codes reference: http://www.restapitutorial.com/httpCodecodes.html
func (*Reply) TemporaryRedirect ¶
TemporaryRedirect method sets the HTTP Code as 307 RFC 7231, 6.4.7.
func (*Reply) Text ¶
Text method renders given data as Plain Text response with given values. Also it sets HTTP Content-Type as 'text/plain; charset=utf-8'.
func (*Reply) Unauthorized ¶
Unauthorized method sets the HTTP Code as 401 RFC 7235, 3.1.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cache
|
|
provider/inmemory
Module
|
|
provider/memcache
Module
|
|
provider/redis
Module
|
|
cli
module
|
|
aah
Module
|
|
ec
|
|
health
Module
|
|
minify
|
|
html
Module
|