Help us shape the future of Go! Take the 2026 Go Developer Survey

vortex

package module
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2019 License: MPL-2.0 Imports: 11 Imported by: 0

README

Vortex

godoc goreportcard

Fast HTTP/s framework with middleware, routing and templating built-in.

Install

go get -u github.com/streamwithme/vortex

Example
server := vortex.NewServer(&vortex.Options{})

server.AddRoute("/", func(request *vortex.Request, response *vortex.Response) {
  response.String("hello world")
})

server.Listen()
Contributing

Pull requests are encouraged.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CookieJar

type CookieJar []*http.Cookie

CookieJar is an abstraction of the []*http.Cookie slice.

func (CookieJar) Domain

func (c CookieJar) Domain(domain string) []*http.Cookie

Domain returns cookies who belong to the given domain.

func (CookieJar) Name

func (c CookieJar) Name(name string) (*http.Cookie, error)

Name returns a cookie by the given name.

type EntrySet

type EntrySet map[string]string

EntrySet is a map of keys and their string values.

func (EntrySet) Get

func (e EntrySet) Get(key string) string

Get returns a value for a given key.

func (EntrySet) Has

func (e EntrySet) Has(key string) bool

Has returns whether or not a key exists.

func (EntrySet) Set

func (e EntrySet) Set(key string, value string)

Set assigns a new value to a given key.

type Handler

type Handler func(*Request, *Response)

Handler -

type Options

type Options struct {
	Host               string   `json:"host"`              // optional, defaults to localhost
	Port               int      `json:"port"`              // optional, defaults to 80
	Directory          string   `json:"directory"`         // optional, relative to current working directory
	FriendlyExtensions []string `json:"friendlyURLs"`      // remove extension requirement in url
	TemplateExtensions []string `json:"templateExtension"` // which extension to associate with templates (.tmp is default)
	Certificate        string   `json:"certificate"`       // optional
	Key                string   `json:"key"`               // optional
}

Options are configurable server settings. All are optional and have default values.

func (*Options) HostOrDefault

func (o *Options) HostOrDefault() string

HostOrDefault -

func (*Options) HostWithPort

func (o *Options) HostWithPort() string

HostWithPort -

func (*Options) PortOrDefault

func (o *Options) PortOrDefault() int

PortOrDefault -

type Request

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

Request is an abstraction of the http.Request.

func (*Request) Body

func (r *Request) Body() string

Body returns the string value of the request body.

func (*Request) Cookies

func (r *Request) Cookies() CookieJar

Cookies returns all the cookies sent in this request.

func (*Request) Header

func (r *Request) Header() http.Header

Header returns the http.Header of the request.

func (*Request) Host

func (r *Request) Host() string

Host returns the source host of the request.

func (*Request) IP

func (r *Request) IP() string

IP returns the source IP of the request.

func (*Request) JSON

func (r *Request) JSON(pointer interface{}) error

JSON decodes the JSON value (if any) of the request body.

func (*Request) Method

func (r *Request) Method() string

Method returns the HTTP method used for this request.

func (*Request) Params

func (r *Request) Params() EntrySet

Params returns named route parameters as a map.

func (*Request) Path

func (r *Request) Path() string

Path returns the path part of the request URL.

func (*Request) Protocol

func (r *Request) Protocol() string

Protocol returns the request protocol string.

func (*Request) Query

func (r *Request) Query() url.Values

Query returns a map of query keys and their values.

func (*Request) Request

func (r *Request) Request() *http.Request

Request returns the original http.Request.

func (*Request) Route

func (r *Request) Route() string

Route returns the currently matched route.

func (*Request) Secure

func (r *Request) Secure() bool

Secure returns whether or not the protocol is https.

func (*Request) Server

func (r *Request) Server() *Server

Server returns the server which received the request.

func (*Request) URL

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

URL returns the url.URL associated with the request.

type Response

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

Response is an abstraction of the http.ResponseWriter.

func (*Response) Bytes

func (r *Response) Bytes(body []byte) error

Bytes responds to the request with raw bytes.

func (*Response) Cookie

func (r *Response) Cookie(cookie *http.Cookie)

Cookie adds the provided cookie to the session.

func (*Response) DestroyCookie

func (r *Response) DestroyCookie(cookie *http.Cookie)

DestroyCookie removes the provided cookie from the session.

func (*Response) End

func (r *Response) End(statusCode int)

End completes the response with a given status code.

func (*Response) Ended

func (r *Response) Ended() bool

Ended returns whether or not the response has ended.

func (*Response) File

func (r *Response) File(path string) error

File responds with a resource relative to the server directory. An extension is required to get the MIME type.

func (*Response) Header

func (r *Response) Header() http.Header

Header returns the header of the response.

func (*Response) JSON

func (r *Response) JSON(body interface{}) error

JSON responds to the request with a struct.

func (*Response) Locals

func (r *Response) Locals() EntrySet

Locals is a key/value store of variables scoped to this response.

func (*Response) Redirect

func (r *Response) Redirect(url string)

Redirect completes the response with a redirection.

func (*Response) Render

func (r *Response) Render(name string, data interface{}) error

Render responds to the request with a template.

func (*Response) Response

func (r *Response) Response() http.ResponseWriter

Response returns the original http.ResponseWriter of the request.

func (*Response) Server

func (r *Response) Server() *Server

Server returns the server which will send the response.

func (*Response) String

func (r *Response) String(body string) error

String responds to the request with a string body.

type Router

type Router func(*Server, *Request) (Handler, error)

Router is a function that maps requests to a handler.

func (Router) Must

func (r Router) Must(server *Server, request *Request) Handler

Must return a handler, regardless of errors.

type Server

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

Server -

func NewServer

func NewServer(options *Options) *Server

NewServer returns a new vortex server.

func (*Server) AddMiddleware

func (s *Server) AddMiddleware(handler ...Handler)

AddMiddleware adds a new middleware to the server. The order in which middleware is added determines the execution order. Middleware will gets called before routing takes place.

func (*Server) AddRoute

func (s *Server) AddRoute(path string, handler Handler)

AddRoute maps a path to a handler.

func (*Server) Listen

func (s *Server) Listen()

Listen starts the http(s) server and blocks.

func (*Server) Middleware

func (s *Server) Middleware() []Handler

Middleware the server is using.

func (*Server) Options

func (s *Server) Options() *Options

Options returns the configurable settings for this server.

func (*Server) Resource

func (s *Server) Resource(path string) ([]byte, error)

Resource fetches the raw bytes from a provided resource path. The path will be translated relative to specified the server directory.

func (*Server) ResourcePath

func (s *Server) ResourcePath(path string) string

ResourcePath fetches the relative to the requested file.

func (*Server) Routes

func (s *Server) Routes() map[string]Handler

Routes returns paths and their corresponding handlers.

func (*Server) Template

func (s *Server) Template(name string) (*template.Template, error)

Template returns a defined template.

Jump to

Keyboard shortcuts

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