Documentation
¶
Index ¶
- Constants
- Variables
- func NewHTTPClient() httpClient
- type ClientChunkFunction
- type ClientHTTPRequest
- func (r *ClientHTTPRequest) AddHeader(key string, value string)
- func (r *ClientHTTPRequest) Chunked()
- func (r *ClientHTTPRequest) CloseConnection()
- func (r *ClientHTTPRequest) Done()
- func (r *ClientHTTPRequest) GetHeader(key string) []string
- func (r *ClientHTTPRequest) HasHeaderValue(key string, value string) bool
- func (r *ClientHTTPRequest) Headers() Headers
- func (r *ClientHTTPRequest) OnChunkFunction(onChunk ClientChunkFunction)
- func (r *ClientHTTPRequest) SendChunk(chunk []byte)
- func (r *ClientHTTPRequest) SetBody(body []byte)
- func (r *ClientHTTPRequest) SetHeader(key string, value string)
- func (r *ClientHTTPRequest) SetTimeout(timeout_ms time.Duration)
- func (r *ClientHTTPRequest) SetURI(uri string) error
- func (r *ClientHTTPRequest) SetVersion(version string) error
- func (r *ClientHTTPRequest) Version() string
- type ClientHTTPResponse
- func (r *ClientHTTPResponse) AddHeader(key string, value string)
- func (r *ClientHTTPResponse) Cookies() []*Cookie
- func (r *ClientHTTPResponse) ExistsHeader(key string) bool
- func (r *ClientHTTPResponse) GetBody() io.Reader
- func (r *ClientHTTPResponse) GetHeader(key string) []string
- func (r *ClientHTTPResponse) HasBody() bool
- func (r *ClientHTTPResponse) HasHeaderValue(key string, value string) bool
- func (r *ClientHTTPResponse) Headers() Headers
- func (r *ClientHTTPResponse) Read(buffer []byte) (int, error)
- func (r *ClientHTTPResponse) SetHeader(key string, value string)
- func (r *ClientHTTPResponse) Version() string
- type Cookie
- type CookieStorage
- type HTTPServer
- func (s *HTTPServer) Close() error
- func (s *HTTPServer) GracefullShutdown() error
- func (s *HTTPServer) HandleDELETE(uriPattern string, handlerFunction ResponseFunction)
- func (s *HTTPServer) HandleDELETEWithOptions(uriPattern string, handlerFunction ResponseFunction, options HandlerOptions)
- func (s *HTTPServer) HandleGET(uriPattern string, handlerFunction ResponseFunction)
- func (s *HTTPServer) HandleGETWithOptions(uriPattern string, handlerFunction ResponseFunction, options HandlerOptions)
- func (s *HTTPServer) HandlePATCH(uriPattern string, handlerFunction ResponseFunction)
- func (s *HTTPServer) HandlePATCHWithOptions(uriPattern string, handlerFunction ResponseFunction, options HandlerOptions)
- func (s *HTTPServer) HandlePOST(uriPattern string, handlerFunction ResponseFunction)
- func (s *HTTPServer) HandlePOSTWithOptions(uriPattern string, handlerFunction ResponseFunction, options HandlerOptions)
- func (s *HTTPServer) HandlePUT(uriPattern string, handlerFunction ResponseFunction)
- func (s *HTTPServer) HandlePUTWithOptions(uriPattern string, handlerFunction ResponseFunction, options HandlerOptions)
- func (s *HTTPServer) Run()
- func (s *HTTPServer) SetTimeout(timeout_ms time.Duration)
- type HandlerOptions
- type Headers
- type ResponseFunction
- type SameSite
- type ServerChunkFunction
- type ServerHTTPRequest
- func (r *ServerHTTPRequest) AddHeader(key string, value string)
- func (r *ServerHTTPRequest) Chunked()
- func (r *ServerHTTPRequest) Cookies() map[string]string
- func (r *ServerHTTPRequest) Done()
- func (r *ServerHTTPRequest) ExistsHeader(key string) bool
- func (r *ServerHTTPRequest) GetHeader(key string) []string
- func (r *ServerHTTPRequest) HasHeaderValue(key string, value string) bool
- func (r *ServerHTTPRequest) Headers() Headers
- func (r *ServerHTTPRequest) ParseForm() (map[string]string, error)
- func (r *ServerHTTPRequest) Path() string
- func (r *ServerHTTPRequest) QueryValues() url.Values
- func (r *ServerHTTPRequest) SendChunk(chunk []byte)
- func (r *ServerHTTPRequest) SetHeader(key string, value string)
- func (r *ServerHTTPRequest) SetVersion(version string) error
- func (r *ServerHTTPRequest) Version() string
- type ServerHTTPResponse
- func (r *ServerHTTPResponse) AddHeader(key string, value string)
- func (r *ServerHTTPResponse) ExistsHeader(key string) bool
- func (r *ServerHTTPResponse) GetHeader(key string) []string
- func (r *ServerHTTPResponse) HasBody() bool
- func (r *ServerHTTPResponse) Headers() Headers
- func (r *ServerHTTPResponse) Read(buffer []byte) (int, error)
- func (r *ServerHTTPResponse) SendChunk() (int, error)
- func (r *ServerHTTPResponse) SendFile(fileName string) error
- func (r *ServerHTTPResponse) SetCookie(cookie *Cookie)
- func (r *ServerHTTPResponse) SetHeader(key string, value string)
- func (r *ServerHTTPResponse) SetStatus(status int)
- func (r *ServerHTTPResponse) Write(p []byte) (n int, err error)
Constants ¶
const ( SAME_SITE_DEFAULT = iota SAME_SITE_LAX SAME_SITE_STRICT SAME_SITE_NONE )
const ( MethodGet = "GET" MethodHead = "HEAD" MethodPost = "POST" MethodPut = "PUT" MethodPatch = "PATCH" MethodDelete = "DELETE" MethodConnect = "CONNECT" MethodOptions = "OPTIONS" MethodTrace = "TRACE" )
HTTP Methods
const ( STATUS_CONTINUE = 100 STATUS_SWITCHING_PROTOCOL = 101 STATUS_OK = 200 STATUS_CREATED = 201 STATUS_ACCEPTED = 202 STATUS_NON_AUTHORATIVE_INFORMATION = 203 STATUS_NO_CONTENT = 204 STATUS_RESET_CONTENT = 205 STATUS_PARTIAL_CONTENT = 206 STATUS_MULTIPLE_CHOICES = 300 STATUS_MOVED_PERMANENTLY = 301 STATUS_FOUND = 302 STATUS_SEE_OTHER = 303 STATUS_NOT_MODIFIED = 304 STATUS_USE_PROXY = 305 STATUS_UNUSED = 306 STATUS_TEMPORARY_REDIRECT = 307 STATUS_PERMANENT_REDIRECT = 308 STATUS_BAD_REQUEST = 400 STATUS_UNAUTHORIZED = 401 STATUS_PAYMENT_REQUIRED = 402 STATUS_FORBIDDEN = 403 STATUS_NOT_FOUND = 404 STATUS_METHOD_NOT_ALLOWED = 405 STATUS_NOT_ACCEPTABLE = 406 STATUS_PROXY_AUTHENTICATION_REQUIRED = 407 STATUS_REQUEST_TIMEOUT = 408 STATUS_CONFLICT = 409 STATUS_GONE = 410 STATUS_LENGTH_REQUIRED = 411 STATUS_PRECONDITION_FAILED = 412 STATUS_CONTENT_TOO_LARGE = 413 STATUS_URI_TOO_LONG = 414 STATUS_UNSUPPORTED_MEDIA_TYPE = 415 STATUS_RANGE_NOT_SATISFIABLE = 416 STATUS_MISDIRECTED_REQUEST = 421 STATUS_UNPROCESSABLE_CONTENT = 422 STATUS_UPGRADE_REQUIRED = 426 STATUS_INTERNAL_ERROR = 500 STATUS_NOT_IMPLEMENTED = 501 STATUS_BAD_GATEWAY = 502 STATUS_SERVICE_UNAVAILABLE = 503 STATUS_GATEWAY_TIMEOUT = 504 STATUS_HTTP_VERSION_NOT_SUPPORTED = 505 )
HTTP Status
const KEEP_ALIVE_TIMEOUT = 5
Variables ¶
var ErrBadRequest = errors.New("bad request")
var ErrClientTimeout = errors.New("client timeout")
var ErrInternalError = errors.New("internal error")
var ErrInvalidLength = errors.New("invalid content length")
var ErrInvalidMethod = errors.New("invalid method")
var ErrMethodNotAllowed = errors.New("method not allowed")
var ErrNotFound = errors.New("not found")
var ErrRequestTimeout = errors.New("request timeout")
var ErrVersionNotSupported = errors.New("version not supported")
Functions ¶
func NewHTTPClient ¶
func NewHTTPClient() httpClient
Types ¶
type ClientChunkFunction ¶
type ClientChunkFunction func([]byte, *ClientHTTPResponse) bool
Function that responds to HTTP Response Chunk on Client Requests
type ClientHTTPRequest ¶
type ClientHTTPRequest struct {
// contains filtered or unexported fields
}
func NewRequest ¶
func NewRequest(uri string) (ClientHTTPRequest, error)
func NewRequestWithBody ¶
func NewRequestWithBody(uri string, body []byte) (ClientHTTPRequest, error)
func (*ClientHTTPRequest) AddHeader ¶
func (r *ClientHTTPRequest) AddHeader(key string, value string)
func (*ClientHTTPRequest) Chunked ¶
func (r *ClientHTTPRequest) Chunked()
func (*ClientHTTPRequest) CloseConnection ¶
func (r *ClientHTTPRequest) CloseConnection()
func (*ClientHTTPRequest) Done ¶
func (r *ClientHTTPRequest) Done()
func (*ClientHTTPRequest) GetHeader ¶
func (r *ClientHTTPRequest) GetHeader(key string) []string
func (*ClientHTTPRequest) HasHeaderValue ¶
func (r *ClientHTTPRequest) HasHeaderValue(key string, value string) bool
func (*ClientHTTPRequest) Headers ¶
func (r *ClientHTTPRequest) Headers() Headers
func (*ClientHTTPRequest) OnChunkFunction ¶
func (r *ClientHTTPRequest) OnChunkFunction(onChunk ClientChunkFunction)
func (*ClientHTTPRequest) SendChunk ¶
func (r *ClientHTTPRequest) SendChunk(chunk []byte)
func (*ClientHTTPRequest) SetBody ¶
func (r *ClientHTTPRequest) SetBody(body []byte)
func (*ClientHTTPRequest) SetHeader ¶
func (r *ClientHTTPRequest) SetHeader(key string, value string)
func (*ClientHTTPRequest) SetTimeout ¶
func (r *ClientHTTPRequest) SetTimeout(timeout_ms time.Duration)
func (*ClientHTTPRequest) SetURI ¶
func (r *ClientHTTPRequest) SetURI(uri string) error
func (*ClientHTTPRequest) SetVersion ¶
func (r *ClientHTTPRequest) SetVersion(version string) error
func (*ClientHTTPRequest) Version ¶
func (r *ClientHTTPRequest) Version() string
type ClientHTTPResponse ¶
type ClientHTTPResponse struct { StatusCode int // contains filtered or unexported fields }
func (*ClientHTTPResponse) AddHeader ¶
func (r *ClientHTTPResponse) AddHeader(key string, value string)
func (*ClientHTTPResponse) Cookies ¶
func (r *ClientHTTPResponse) Cookies() []*Cookie
func (*ClientHTTPResponse) ExistsHeader ¶
func (r *ClientHTTPResponse) ExistsHeader(key string) bool
func (*ClientHTTPResponse) GetBody ¶
func (r *ClientHTTPResponse) GetBody() io.Reader
func (*ClientHTTPResponse) GetHeader ¶
func (r *ClientHTTPResponse) GetHeader(key string) []string
func (*ClientHTTPResponse) HasBody ¶
func (r *ClientHTTPResponse) HasBody() bool
func (*ClientHTTPResponse) HasHeaderValue ¶
func (r *ClientHTTPResponse) HasHeaderValue(key string, value string) bool
func (*ClientHTTPResponse) Headers ¶
func (r *ClientHTTPResponse) Headers() Headers
func (*ClientHTTPResponse) SetHeader ¶
func (r *ClientHTTPResponse) SetHeader(key string, value string)
func (*ClientHTTPResponse) Version ¶
func (r *ClientHTTPResponse) Version() string
type Cookie ¶
type CookieStorage ¶
type CookieStorage struct {
// contains filtered or unexported fields
}
func (*CookieStorage) SetCookies ¶
func (cs *CookieStorage) SetCookies(url *url.URL, cookies []*Cookie)
type HTTPServer ¶
type HTTPServer struct {
// contains filtered or unexported fields
}
Struct that represent a HTTP Server
func NewHTTPServer ¶
func NewHTTPServer(address string) (*HTTPServer, error)
Create a HTTP Server listening in address
func NewTLSHTTPServer ¶
func NewTLSHTTPServer(address string, config *tls.Config) (*HTTPServer, error)
Create a HTTPS Server listening in address
func (*HTTPServer) GracefullShutdown ¶
func (s *HTTPServer) GracefullShutdown() error
Gracefully shutdown server waiting for open connections to finish
func (*HTTPServer) HandleDELETE ¶
func (s *HTTPServer) HandleDELETE(uriPattern string, handlerFunction ResponseFunction)
Add Handler for DELETE method to given uri pattern
func (*HTTPServer) HandleDELETEWithOptions ¶
func (s *HTTPServer) HandleDELETEWithOptions(uriPattern string, handlerFunction ResponseFunction, options HandlerOptions)
Add Handler for DELETE method to given uri pattern with additional options
func (*HTTPServer) HandleGET ¶
func (s *HTTPServer) HandleGET(uriPattern string, handlerFunction ResponseFunction)
Add Handler for GET method to given uri pattern
func (*HTTPServer) HandleGETWithOptions ¶
func (s *HTTPServer) HandleGETWithOptions(uriPattern string, handlerFunction ResponseFunction, options HandlerOptions)
Add Handler for GET method to given uri pattern with additional options
func (*HTTPServer) HandlePATCH ¶
func (s *HTTPServer) HandlePATCH(uriPattern string, handlerFunction ResponseFunction)
Add Handler for PATCH method to given uri pattern
func (*HTTPServer) HandlePATCHWithOptions ¶
func (s *HTTPServer) HandlePATCHWithOptions(uriPattern string, handlerFunction ResponseFunction, options HandlerOptions)
Add Handler for PATCH method to given uri pattern with additional options
func (*HTTPServer) HandlePOST ¶
func (s *HTTPServer) HandlePOST(uriPattern string, handlerFunction ResponseFunction)
Add Handler for POST method to given uri pattern
func (*HTTPServer) HandlePOSTWithOptions ¶
func (s *HTTPServer) HandlePOSTWithOptions(uriPattern string, handlerFunction ResponseFunction, options HandlerOptions)
Add Handler for POST method to given uri pattern with additional options
func (*HTTPServer) HandlePUT ¶
func (s *HTTPServer) HandlePUT(uriPattern string, handlerFunction ResponseFunction)
Add Handler for PUT method to given uri pattern
func (*HTTPServer) HandlePUTWithOptions ¶
func (s *HTTPServer) HandlePUTWithOptions(uriPattern string, handlerFunction ResponseFunction, options HandlerOptions)
Add Handler for PUT method to given uri pattern with additional options
func (*HTTPServer) Run ¶
func (s *HTTPServer) Run()
Start listening to requests. This method blocks until server is closed
func (*HTTPServer) SetTimeout ¶
func (s *HTTPServer) SetTimeout(timeout_ms time.Duration)
Function that sets server request timeout
type HandlerOptions ¶
type HandlerOptions struct {
// contains filtered or unexported fields
}
Additional Options for Handlers
type ResponseFunction ¶
type ResponseFunction func(ServerHTTPRequest, *ServerHTTPResponse)
Function that responds to HTTP Requests
func FileServer ¶
func FileServer(fileName string) ResponseFunction
Response Function that responds to a request with the file indicated by fileName
func FileServerFromPath ¶
func FileServerFromPath(filePrefix string) ResponseFunction
Response Function that responds to a request with the file indicated by filePrefix + lastPathElement
func PermaRedirect ¶
func PermaRedirect(redirectURI string) ResponseFunction
Response Function that responds to a request with a perma redirect to given redirectURI
type ServerChunkFunction ¶
type ServerChunkFunction func([]byte, ServerHTTPRequest, *ServerHTTPResponse) bool
Function that responds to HTTP Request Chunk
type ServerHTTPRequest ¶
type ServerHTTPRequest struct { Body []byte // contains filtered or unexported fields }
func (*ServerHTTPRequest) AddHeader ¶
func (r *ServerHTTPRequest) AddHeader(key string, value string)
func (*ServerHTTPRequest) Chunked ¶
func (r *ServerHTTPRequest) Chunked()
func (*ServerHTTPRequest) Cookies ¶
func (r *ServerHTTPRequest) Cookies() map[string]string
func (*ServerHTTPRequest) Done ¶
func (r *ServerHTTPRequest) Done()
func (*ServerHTTPRequest) ExistsHeader ¶
func (r *ServerHTTPRequest) ExistsHeader(key string) bool
func (*ServerHTTPRequest) GetHeader ¶
func (r *ServerHTTPRequest) GetHeader(key string) []string
func (*ServerHTTPRequest) HasHeaderValue ¶
func (r *ServerHTTPRequest) HasHeaderValue(key string, value string) bool
func (*ServerHTTPRequest) Headers ¶
func (r *ServerHTTPRequest) Headers() Headers
func (*ServerHTTPRequest) ParseForm ¶
func (r *ServerHTTPRequest) ParseForm() (map[string]string, error)
func (*ServerHTTPRequest) Path ¶
func (r *ServerHTTPRequest) Path() string
func (*ServerHTTPRequest) QueryValues ¶
func (r *ServerHTTPRequest) QueryValues() url.Values
func (*ServerHTTPRequest) SendChunk ¶
func (r *ServerHTTPRequest) SendChunk(chunk []byte)
func (*ServerHTTPRequest) SetHeader ¶
func (r *ServerHTTPRequest) SetHeader(key string, value string)
func (*ServerHTTPRequest) SetVersion ¶
func (r *ServerHTTPRequest) SetVersion(version string) error
func (*ServerHTTPRequest) Version ¶
func (r *ServerHTTPRequest) Version() string
type ServerHTTPResponse ¶
type ServerHTTPResponse struct {
// contains filtered or unexported fields
}
func (*ServerHTTPResponse) AddHeader ¶
func (r *ServerHTTPResponse) AddHeader(key string, value string)
func (*ServerHTTPResponse) ExistsHeader ¶
func (r *ServerHTTPResponse) ExistsHeader(key string) bool
func (*ServerHTTPResponse) GetHeader ¶
func (r *ServerHTTPResponse) GetHeader(key string) []string
func (*ServerHTTPResponse) HasBody ¶
func (r *ServerHTTPResponse) HasBody() bool
func (*ServerHTTPResponse) Headers ¶
func (r *ServerHTTPResponse) Headers() Headers
func (*ServerHTTPResponse) SendChunk ¶
func (r *ServerHTTPResponse) SendChunk() (int, error)
func (*ServerHTTPResponse) SendFile ¶
func (r *ServerHTTPResponse) SendFile(fileName string) error
func (*ServerHTTPResponse) SetCookie ¶
func (r *ServerHTTPResponse) SetCookie(cookie *Cookie)
func (*ServerHTTPResponse) SetHeader ¶
func (r *ServerHTTPResponse) SetHeader(key string, value string)
func (*ServerHTTPResponse) SetStatus ¶
func (r *ServerHTTPResponse) SetStatus(status int)