Documentation
¶
Index ¶
- func ETag(b []byte) string
- func ETagString(b string) string
- func IsMediaType(contentType string) bool
- type Application
- func (app *Application) AddPushCondition(test func(*Context) bool)
- func (app *Application) Get(path string, handle Handle)
- func (app *Application) Handler() http.Handler
- func (app *Application) ListenAndServe()
- func (app *Application) Load()
- func (app *Application) OnEnd(callback func())
- func (app *Application) OnPush(callback func(*Context))
- func (app *Application) OnStart(callback func())
- func (app *Application) Post(path string, handle Handle)
- func (app *Application) Rewrite(rewrite func(*RewriteContext))
- func (app *Application) Run()
- func (app *Application) Shutdown()
- func (app *Application) StartTime() time.Time
- func (app *Application) Test(route string, paths []string)
- func (app *Application) TestManifest()
- func (app *Application) TestRoute(route string, uri string)
- func (app *Application) TestRoutes()
- func (app *Application) Use(middlewares ...Middleware)
- func (app *Application) Wait()
- type ApplicationSecurity
- type Body
- type Configuration
- type Context
- func (ctx *Context) CSS(text string) string
- func (ctx *Context) Error(statusCode int, errors ...interface{}) string
- func (ctx *Context) EventStream(stream *EventStream) string
- func (ctx *Context) File(file string) string
- func (ctx *Context) Get(param string) string
- func (ctx *Context) GetInt(param string) (int, error)
- func (ctx *Context) HTML(html string) string
- func (ctx *Context) HasSession() bool
- func (ctx *Context) JSON(value interface{}) string
- func (ctx *Context) JSONLinkedData(value interface{}) string
- func (ctx *Context) JavaScript(code string) string
- func (ctx *Context) Query(param string) string
- func (ctx *Context) ReadAll(reader io.Reader) string
- func (ctx *Context) ReadSeeker(reader io.ReadSeeker) string
- func (ctx *Context) Reader(reader io.Reader) string
- func (ctx *Context) RealIP() string
- func (ctx *Context) Redirect(url string) string
- func (ctx *Context) RedirectPermanently(url string) string
- func (ctx *Context) Request() Request
- func (ctx *Context) Response() Response
- func (ctx *Context) Session() *session.Session
- func (ctx *Context) SetURI(b string)
- func (ctx *Context) Text(text string) string
- func (ctx *Context) URI() string
- func (ctx *Context) UserAgent() string
- type Event
- type EventStream
- type Handle
- type Linter
- type Listener
- type Manifest
- type ManifestIcon
- type Middleware
- type PortConfiguration
- type Request
- type Response
- type RewriteContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ETag ¶
ETag produces a hash for the given slice of bytes. It is the same hash that Aero uses for its ETag header.
func ETagString ¶
ETagString produces a hash for the given string. It is the same hash that Aero uses for its ETag header.
func IsMediaType ¶
IsMediaType returns whether the given content type is a media type.
Types ¶
type Application ¶
type Application struct { Config *Configuration Sessions session.Manager Security ApplicationSecurity Linters []Linter Router *httprouter.Router ContentSecurityPolicy *csp.ContentSecurityPolicy // contains filtered or unexported fields }
Application represents a single web service.
func (*Application) AddPushCondition ¶
func (app *Application) AddPushCondition(test func(*Context) bool)
AddPushCondition registers a callback to be executed when an HTTP/2 push happens.
func (*Application) Get ¶
func (app *Application) Get(path string, handle Handle)
Get registers your function to be called when a certain GET path has been requested.
func (*Application) Handler ¶
func (app *Application) Handler() http.Handler
Handler returns the request handler used by the application.
func (*Application) ListenAndServe ¶
func (app *Application) ListenAndServe()
ListenAndServe starts the server. It guarantees that a TCP listener is listening on the ports defined in the config when the function returns.
func (*Application) Load ¶
func (app *Application) Load()
Load loads the application configuration from config.json.
func (*Application) OnEnd ¶
func (app *Application) OnEnd(callback func())
OnEnd registers a callback to be executed on server shutdown.
func (*Application) OnPush ¶
func (app *Application) OnPush(callback func(*Context))
OnPush registers a callback to be executed when an HTTP/2 push happens.
func (*Application) OnStart ¶
func (app *Application) OnStart(callback func())
OnStart registers a callback to be executed on server start.
func (*Application) Post ¶
func (app *Application) Post(path string, handle Handle)
Post registers your function to be called when a certain POST path has been requested.
func (*Application) Rewrite ¶
func (app *Application) Rewrite(rewrite func(*RewriteContext))
Rewrite sets the URL rewrite function.
func (*Application) Shutdown ¶
func (app *Application) Shutdown()
Shutdown will gracefully shut down all servers.
func (*Application) StartTime ¶
func (app *Application) StartTime() time.Time
StartTime returns the time the application started.
func (*Application) Test ¶
func (app *Application) Test(route string, paths []string)
Test tests the given URI paths when the application starts.
func (*Application) TestManifest ¶
func (app *Application) TestManifest()
TestManifest tests your application's manifest.
func (*Application) TestRoute ¶
func (app *Application) TestRoute(route string, uri string)
TestRoute tests the given route.
func (*Application) TestRoutes ¶
func (app *Application) TestRoutes()
TestRoutes tests your application's routes.
func (*Application) Use ¶
func (app *Application) Use(middlewares ...Middleware)
Use adds middleware to your middleware chain.
func (*Application) Wait ¶
func (app *Application) Wait()
Wait will make the process wait until it is killed.
type ApplicationSecurity ¶
ApplicationSecurity stores the certificate data.
func (*ApplicationSecurity) Load ¶
func (security *ApplicationSecurity) Load(certificate string, key string)
Load expects the path of the certificate and the key.
type Body ¶ added in v1.1.8
type Body struct {
// contains filtered or unexported fields
}
Body represents a request body.
func (Body) JSONObject ¶ added in v1.1.8
JSONObject parses the body as a JSON object and returns a map[string]interface{}.
func (Body) Reader ¶ added in v1.1.8
func (body Body) Reader() io.ReadCloser
Reader returns an io.Reader for the request body.
type Configuration ¶
type Configuration struct { Domain string `json:"domain"` Title string `json:"title"` Push []string `json:"push"` Manifest Manifest `json:"manifest"` GZip bool `json:"gzip"` Ports PortConfiguration `json:"ports"` }
Configuration represents the data in your config.json file.
func LoadConfig ¶
func LoadConfig(path string) (*Configuration, error)
LoadConfig loads the application configuration from the file system.
func (*Configuration) Reset ¶
func (config *Configuration) Reset()
Reset resets all fields to the default configuration.
type Context ¶
type Context struct { // A pointer to the application this request occurred on. App *Application // Status code StatusCode int // Error message ErrorMessage string // Custom data Data interface{} // contains filtered or unexported fields }
Context represents a single request & response.
func (*Context) EventStream ¶
func (ctx *Context) EventStream(stream *EventStream) string
EventStream sends server events to the client.
func (*Context) File ¶
File sends the contents of a local file and determines its mime type by extension.
func (*Context) HasSession ¶
HasSession indicates whether the client has a valid session or not.
func (*Context) JSONLinkedData ¶
JSONLinkedData encodes the object to a JSON linked data string and responds.
func (*Context) JavaScript ¶
JavaScript sends a script.
func (*Context) ReadAll ¶
ReadAll returns the contents of the reader. This will create an in-memory copy and calculate the E-Tag before sending the data. Compression will be applied if necessary.
func (*Context) ReadSeeker ¶
func (ctx *Context) ReadSeeker(reader io.ReadSeeker) string
ReadSeeker sends the contents of the io.ReadSeeker without creating an in-memory copy. E-Tags will not be generated for the content and compression will not be applied. Use this function if your reader contains huge amounts of data.
func (*Context) Reader ¶
Reader sends the contents of the io.Reader without creating an in-memory copy. E-Tags will not be generated for the content and compression will not be applied. Use this function if your reader contains huge amounts of data.
func (*Context) RedirectPermanently ¶
RedirectPermanently redirects to the given URL and indicates that this is a permanent change using status code 301.
func (*Context) Session ¶
Session returns the session of the context or creates and caches a new session.
type Event ¶
type Event struct { Name string Data interface{} }
Event represents a single event in an event stream.
type EventStream ¶
type EventStream struct { Events chan *Event Closed chan struct{} }
EventStream includes a channel of events that we can send to and a closed channel that we can check for closed connections.
type Linter ¶
type Linter interface { Begin(route string, uri string) End(route string, uri string, response *client.Response) }
Linter interface defines Begin and End methods that linters can implement.
type Listener ¶
type Listener struct {
*net.TCPListener
}
Listener sets TCP keep-alive timeouts on accepted connections.
type Manifest ¶
type Manifest struct { Name string `json:"name"` ShortName string `json:"short_name"` Icons []ManifestIcon `json:"icons,omitempty"` StartURL string `json:"start_url"` Display string `json:"display"` Lang string `json:"lang,omitempty"` ThemeColor string `json:"theme_color,omitempty"` BackgroundColor string `json:"background_color,omitempty"` }
Manifest represents a web manifest
type ManifestIcon ¶
type ManifestIcon struct { Source string `json:"src"` Sizes string `json:"sizes"` Type string `json:"type"` }
ManifestIcon represents a single icon in the web manifest.
type Middleware ¶
type Middleware func(*Context, func())
Middleware is a function that accepts a context and the next function in the call chain.
type PortConfiguration ¶
PortConfiguration lets you configure the ports that Aero will listen on.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request represents the HTTP request used in the given context.
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response represents the HTTP response used in the given context.
type RewriteContext ¶
RewriteContext is used for the URI rewrite ability.
func (*RewriteContext) SetURI ¶
func (ctx *RewriteContext) SetURI(b string)
SetURI sets the relative path, e.g. /blog/post/123.
func (*RewriteContext) URI ¶
func (ctx *RewriteContext) URI() string
URI returns the relative path, e.g. /blog/post/123.