ws

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2021 License: MIT Imports: 15 Imported by: 4

Documentation

Overview

Package ws provides a simple RESTful web server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsOK added in v0.0.4

func IsOK(err error) bool

IsOK checks if the error is status ok.

Types

type Context

type Context struct {
	ResponseWriter http.ResponseWriter
	Request        *http.Request
	Reader         io.ReadCloser
	Path           string
	// contains filtered or unexported fields
}

Context represents the context which hold the HTTP request and response.

func (*Context) Content

func (a *Context) Content(name string, modtime time.Time, content io.ReadSeeker) error

Content responses the content.

func (*Context) DecodeJSON

func (a *Context) DecodeJSON(value interface{}) error

DecodeJSON decodes the JSON data.

func (*Context) DecodeXML

func (a *Context) DecodeXML(value interface{}) error

DecodeXML decodes the XML data.

func (*Context) File

func (a *Context) File(path string) error

File responses the file content.

func (*Context) Form added in v0.0.4

func (a *Context) Form(key string) string

Form returns the first value for the named component of the request body.

func (*Context) FormAll added in v0.0.4

func (a *Context) FormAll(key string) []string

FormAll returns the values for the named component of the request body.

func (*Context) FormBool added in v0.0.4

func (a *Context) FormBool(key string) (bool, error)

FormBool return the param as bool by key.

func (*Context) FormFile

func (a *Context) FormFile(key string) (multipart.File, *multipart.FileHeader, error)

FormFile returns the first file for the provided form key.

func (*Context) FormFloat added in v0.0.4

func (a *Context) FormFloat(key string) (float64, error)

FormFloat return the param as float by key.

func (*Context) FormInt added in v0.0.4

func (a *Context) FormInt(key string) (int64, error)

FormInt return the param as int by key.

func (*Context) Get

func (a *Context) Get(key string) interface{}

Get gets the context data.

func (*Context) JSON

func (a *Context) JSON(value interface{}) error

JSON responses the JSON content.

func (*Context) Next

func (a *Context) Next() error

Next calls the next handler.

func (*Context) Param

func (a *Context) Param(key string) string

Param return the param by key.

func (*Context) ParamBool added in v0.0.4

func (a *Context) ParamBool(key string) (bool, error)

ParamBool return the param as bool by key.

func (*Context) ParamFloat added in v0.0.4

func (a *Context) ParamFloat(key string) (float64, error)

ParamFloat return the param as float by key.

func (*Context) ParamInt added in v0.0.4

func (a *Context) ParamInt(key string) (int64, error)

ParamInt return the param as int by key.

func (*Context) Query

func (a *Context) Query(key string) string

Query returns the first value associated with the given key.

func (*Context) QueryAll added in v0.0.2

func (a *Context) QueryAll(key string) []string

QueryAll returns the values associated with the given key.

func (*Context) QueryBool added in v0.0.4

func (a *Context) QueryBool(key string) (bool, error)

QueryBool return the param as bool by key.

func (*Context) QueryFloat added in v0.0.4

func (a *Context) QueryFloat(key string) (float64, error)

QueryFloat return the param as float by key.

func (*Context) QueryInt added in v0.0.4

func (a *Context) QueryInt(key string) (int64, error)

QueryInt return the param as int by key.

func (*Context) RealIP

func (a *Context) RealIP() string

RealIP returns the real client IP.

func (*Context) Set

func (a *Context) Set(key string, value interface{})

Set sets the context data.

func (*Context) Text

func (a *Context) Text(value string) error

Text responses the text content.

func (*Context) XML

func (a *Context) XML(value interface{}) error

XML responses the XML content.

type Router

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

Router represents a router node.

func (*Router) Delete

func (a *Router) Delete(pattern string, hs ...func(*Context) error) *Router

Delete registers the handler for the given pattern and method DELETE.

func (*Router) Get

func (a *Router) Get(pattern string, hs ...func(*Context) error) *Router

Get registers the handler for the given pattern and method GET.

func (*Router) Handle

func (a *Router) Handle(method string, pattern string, hs ...func(*Context) error) *Router

Handle registers the handler for the given pattern and method.

func (*Router) Patch

func (a *Router) Patch(pattern string, hs ...func(*Context) error) *Router

Patch registers the handler for the given pattern and method PATCH.

func (*Router) Post

func (a *Router) Post(pattern string, hs ...func(*Context) error) *Router

Post registers the handler for the given pattern and method POST.

func (*Router) Put

func (a *Router) Put(pattern string, hs ...func(*Context) error) *Router

Put registers the handler for the given pattern and method PUT.

func (*Router) Route

func (a *Router) Route(pattern string) *Router

Route finds the router by pattern.

func (*Router) Use

func (a *Router) Use(hs ...func(*Context) error) *Router

Use uses the middlewares.

type Server

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

Server represents a web server.

func New

func New() *Server

New creates a new server.

func (*Server) Addr added in v0.0.3

func (a *Server) Addr(addr string) *Server

Addr optionally specifies the TCP address for the server to listen on.

func (*Server) Config added in v0.0.3

func (a *Server) Config(f func(s *http.Server)) *Server

Config configures the raw http.Server.

func (*Server) IdleTimeout added in v0.0.3

func (a *Server) IdleTimeout(d time.Duration) *Server

IdleTimeout is the maximum amount of time to wait for the next request when keep-alives are enabled.

func (*Server) MaxHeaderBytes added in v0.0.3

func (a *Server) MaxHeaderBytes(n int) *Server

MaxHeaderBytes controls the maximum number of bytes the server will read parsing the request header's keys and values.

func (*Server) ReadHeaderTimeout added in v0.0.3

func (a *Server) ReadHeaderTimeout(d time.Duration) *Server

ReadHeaderTimeout is the amount of time allowed to read request headers.

func (*Server) ReadTimeout added in v0.0.3

func (a *Server) ReadTimeout(d time.Duration) *Server

ReadTimeout is the maximum duration for reading the entire request, including the body.

func (*Server) Start

func (a *Server) Start() error

Start starts the server.

func (*Server) TLS added in v0.0.3

func (a *Server) TLS(certfile, keyfile string) *Server

TLS sets the certfile and keyfile for TLS.

func (*Server) WriteTimeout added in v0.0.3

func (a *Server) WriteTimeout(d time.Duration) *Server

WriteTimeout is the maximum duration before timing out writes of the response.

type Status

type Status int

Status represents a http status.

func (Status) Error

func (a Status) Error() string

Error implements error interface.

Directories

Path Synopsis
Package cors provides a simple cors middleware.
Package cors provides a simple cors middleware.
Package limiter provides a simple limiter middleware.
Package limiter provides a simple limiter middleware.
Package static provides a simple static file middleware.
Package static provides a simple static file middleware.

Jump to

Keyboard shortcuts

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