aero

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2019 License: MIT Imports: 34 Imported by: 117

README

Aero Go Logo

Godoc reference Go report card Tests Code coverage License

Aero is a high-performance web server with a clean API for web development.

Installation

go get github.com/aerogo/aero/...

Usage

Aero usage

Run this in an empty directory:

aero -newapp

Now you can build your app with go build or use the more advanced run tool.

Features

  • Makes it easy to reach top scores in Lighthouse, PageSpeed and Mozilla Observatory
  • Optimized for high latency environments (mobile networks)
  • Has a strict content security policy
  • Calculates E-Tags out of the box
  • Finishes ongoing requests on a server shutdown
  • Supports HTTP/2, IPv6 and Web Manifest
  • Automatic HTTP/2 push of configured resources
  • Supports session data with custom stores
  • Allows pushing live data to the client via SSE
  • Provides http and https listener
  • Shows response time and size for your routes
  • Can run standalone without nginx babysitting it

Optional

  • layout as a layout system
  • pack to compile Pixy, Scarlet and JS assets in record time
  • run which automatically restarts your server on code/template/style changes
  • pixy as a high-performance template engine similar to Jade/Pug
  • scarlet as an aggressively compressing stylesheet preprocessor
  • nano as a fast, decentralized and git-trackable database
  • api to automatically implement your REST API routes
  • markdown as an overly simplified markdown wrapper
  • http as an HTTP client with a simple and clean API
  • log for simple & performant logging

Documentation

Others

Author

Eduard Urbach on Twitter
Eduard Urbach

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToStringUnsafe

func BytesToStringUnsafe(b []byte) string

BytesToStringUnsafe converts a byte slice to a string. It's fast, but not safe. Use it only if you know what you're doing.

func ETag

func ETag(b []byte) string

ETag produces a hash for the given slice of bytes. It is the same hash that Aero uses for its ETag header.

func ETagString

func ETagString(b string) string

ETagString produces a hash for the given string. It is the same hash that Aero uses for its ETag header.

func IsMediaType

func IsMediaType(contentType string) bool

IsMediaType returns whether the given content type is a media type.

func StringToBytesUnsafe

func StringToBytesUnsafe(s string) []byte

StringToBytesUnsafe converts a string to a byte slice. It's fast, but not safe. Use it only if you know what you're doing.

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 New

func New() *Application

New creates a new application.

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) Run

func (app *Application) Run()

Run starts your application.

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

type ApplicationSecurity struct {
	Key         string
	Certificate string
}

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 BodyReader

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

BodyReader represents a request body.

func (BodyReader) Bytes

func (body BodyReader) Bytes() ([]byte, error)

Bytes returns a slice of bytes containing the request body.

func (BodyReader) JSON

func (body BodyReader) JSON() (interface{}, error)

JSON parses the body as a JSON object.

func (BodyReader) JSONObject

func (body BodyReader) JSONObject() (map[string]interface{}, error)

JSONObject parses the body as a JSON object and returns a map[string]interface{}.

func (BodyReader) String

func (body BodyReader) String() (string, error)

String returns a string containing the request body.

type Configuration

type Configuration struct {
	Domain   string               `json:"domain"`
	Title    string               `json:"title"`
	Fonts    []string             `json:"fonts"`
	Styles   []string             `json:"styles"`
	Scripts  ScriptsConfiguration `json:"scripts"`
	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) CSS

func (ctx *Context) CSS(text string) string

CSS sends a style sheet.

func (*Context) Error

func (ctx *Context) Error(statusCode int, errors ...interface{}) string

Error should be used for sending error messages to the user.

func (*Context) EventStream

func (ctx *Context) EventStream(stream *EventStream) string

EventStream sends server events to the client.

func (*Context) File

func (ctx *Context) File(file string) string

File sends the contents of a local file and determines its mime type by extension.

func (*Context) Get

func (ctx *Context) Get(param string) string

Get retrieves an URL parameter.

func (*Context) GetInt

func (ctx *Context) GetInt(param string) (int, error)

GetInt retrieves an URL parameter as an integer.

func (*Context) HTML

func (ctx *Context) HTML(html string) string

HTML sends a HTML string.

func (*Context) HasSession

func (ctx *Context) HasSession() bool

HasSession indicates whether the client has a valid session or not.

func (*Context) JSON

func (ctx *Context) JSON(value interface{}) string

JSON encodes the object to a JSON string and responds.

func (*Context) JSONLinkedData

func (ctx *Context) JSONLinkedData(value interface{}) string

JSONLinkedData encodes the object to a JSON linked data string and responds.

func (*Context) JavaScript

func (ctx *Context) JavaScript(code string) string

JavaScript sends a script.

func (*Context) Query

func (ctx *Context) Query(param string) string

Query retrieves the value for the given URL query parameter.

func (*Context) ReadAll

func (ctx *Context) ReadAll(reader io.Reader) string

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

func (ctx *Context) Reader(reader io.Reader) string

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) RealIP

func (ctx *Context) RealIP() string

RealIP tries to determine the real IP address of the request.

func (*Context) Redirect

func (ctx *Context) Redirect(url string) string

Redirect redirects to the given URL using status code 302.

func (*Context) RedirectPermanently

func (ctx *Context) RedirectPermanently(url string) string

RedirectPermanently redirects to the given URL and indicates that this is a permanent change using status code 301.

func (*Context) Request

func (ctx *Context) Request() Request

Request returns the HTTP request.

func (*Context) Response

func (ctx *Context) Response() Response

Response returns the HTTP response.

func (*Context) Session

func (ctx *Context) Session() *session.Session

Session returns the session of the context or creates and caches a new session.

func (*Context) SetURI

func (ctx *Context) SetURI(b string)

SetURI sets the relative path, e.g. /blog/post/123.

func (*Context) Text

func (ctx *Context) Text(text string) string

Text sends a plain text string.

func (*Context) URI

func (ctx *Context) URI() string

URI returns the relative path, e.g. /blog/post/123.

func (*Context) UserAgent

func (ctx *Context) UserAgent() string

UserAgent retrieves the user agent for the given request.

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.

func NewEventStream

func NewEventStream() *EventStream

NewEventStream creates a new event stream.

type Handle

type Handle func(*Context) string

Handle is a function that returns a string response for a given context.

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.

func (Listener) Accept

func (listener Listener) Accept() (net.Conn, error)

Accept accepts incoming 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"`
	GCMSenderID     string         `json:"gcm_sender_id,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

type PortConfiguration struct {
	HTTP  int `json:"http"`
	HTTPS int `json:"https"`
}

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.

func (Request) Body

func (request Request) Body() BodyReader

Body represents the request body.

func (Request) Header

func (request Request) Header() http.Header

Header represents the request headers.

func (Request) Host

func (request Request) Host() string

Host returns the requested host.

func (Request) Method

func (request Request) Method() string

Method returns the request method.

func (Request) Protocol

func (request Request) Protocol() string

Protocol returns the request protocol.

func (Request) URL

func (request Request) URL() *url.URL

URL returns the request URL.

type Response

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

Response represents the HTTP response used in the given context.

func (Response) Header

func (response Response) Header() http.Header

Header represents the response headers.

type RewriteContext

type RewriteContext struct {
	Request *http.Request
}

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.

type ScriptsConfiguration

type ScriptsConfiguration struct {
	// Entry point for scripts
	Main string `json:"main"`
}

ScriptsConfiguration lets you configure your main entry script.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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