Documentation
¶
Overview ¶
Package easytls is intended to provide a simplification and abstraction layer for quickly creating HTTP(S) enabled web applications. This module intends to provide a simple API to illustrate the parameters needed for proper TLS security, as well as providing simpler methods for performing standard HTTP(S) operations
Index ¶
- func AddHandlers(verbose bool, s *SimpleServer, r *mux.Router, Handlers ...SimpleHandler)
- func AddMiddlewares(r *mux.Router, middlewares ...MiddlewareHandler)
- func DefaultLoggingMiddleware(next http.Handler) http.Handler
- func NewDefaultRouter() *mux.Router
- func NewRouter(s *SimpleServer, Handlers []SimpleHandler, Middlewares ...MiddlewareHandler) *mux.Router
- func NewTLSConfig(TLS *TLSBundle) (*tls.Config, error)
- type KeyPair
- type MiddlewareHandler
- type SimpleClient
- func (C *SimpleClient) Connect(URL *url.URL, Headers map[string]string) error
- func (C *SimpleClient) Delete(URL *url.URL, Headers map[string]string) error
- func (C *SimpleClient) Get(URL *url.URL, Headers map[string]string) (*http.Response, error)
- func (C *SimpleClient) Head(URL *url.URL, Headers map[string]string) (http.Header, error)
- func (C *SimpleClient) Options(URL *url.URL, Headers map[string]string) error
- func (C *SimpleClient) Patch(URL *url.URL, Headers map[string]string) error
- func (C *SimpleClient) Post(URL *url.URL, contents io.Reader, Headers map[string]string) (*http.Response, error)
- func (C *SimpleClient) Put(URL *url.URL, contents io.Reader, Headers map[string]string) error
- func (C *SimpleClient) Trace(URL *url.URL, Headers map[string]string) error
- type SimpleHandler
- type SimpleServer
- type TLSBundle
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddHandlers ¶ added in v1.0.1
func AddHandlers(verbose bool, s *SimpleServer, r *mux.Router, Handlers ...SimpleHandler)
AddHandlers will add the given handlers to the router, with the verbose flag determining if a log message should be generated for each added route.
func AddMiddlewares ¶ added in v1.0.1
func AddMiddlewares(r *mux.Router, middlewares ...MiddlewareHandler)
AddMiddlewares is a convenience wrapper for the mux.Router "Use" function
func DefaultLoggingMiddleware ¶ added in v1.0.1
DefaultLoggingMiddleware provides a simple logging middleware, to view incoming connections as they arrive.
func NewDefaultRouter ¶ added in v1.0.1
NewDefaultRouter will initialize a new HTTP Router, based on the gorilla/mux implementation.
func NewRouter ¶ added in v1.0.0
func NewRouter(s *SimpleServer, Handlers []SimpleHandler, Middlewares ...MiddlewareHandler) *mux.Router
NewRouter will build a new complex router, with the given routes, and middlewares. More can be added later, if needed.
Types ¶
type MiddlewareHandler ¶ added in v1.0.0
MiddlewareHandler represents the general format for a Middleware handler.
type SimpleClient ¶ added in v1.0.0
type SimpleClient struct {
// contains filtered or unexported fields
}
SimpleClient is a renaming of the Standard http.Client for this package, to allow the ease-of-use extensions provided here.
func NewClientHTTP ¶ added in v1.0.0
func NewClientHTTP() (*SimpleClient, error)
NewClientHTTP will create a new SimpleClient, with no TLS settings enabled. This will accept raw HTTP only.
func NewClientHTTPS ¶ added in v1.0.0
func NewClientHTTPS(TLS *TLSBundle) (*SimpleClient, error)
NewClientHTTPS will create a new TLS-Enabled SimpleClient. This will
func (*SimpleClient) Delete ¶ added in v1.0.0
Delete represents the abstraction of the HTTP Delete request, accounting for creating the request, setting headers, and asserting a valid status code. Closing the response body is the responsibility of this function.
func (*SimpleClient) Get ¶ added in v1.0.0
Get represents the abstraction of the HTTP Get request, accounting for creating the request, setting headers, and asserting a valid status code. Closing the response body is the responsibility of the caller.
func (*SimpleClient) Head ¶ added in v1.0.0
Head represents the abstraction of the HTTP Head request, accounting for creating the request, setting headers, and asserting a valid status code. Closing the response body is the responsibility of this function, as Head only returns the headers.
func (*SimpleClient) Post ¶ added in v1.0.0
func (C *SimpleClient) Post(URL *url.URL, contents io.Reader, Headers map[string]string) (*http.Response, error)
Post represents the abstraction of the HTTP Post request, accounting for creating the request, setting headers, and asserting a valid status code. Closing the response body is the responsibility of the caller.
type SimpleHandler ¶ added in v1.0.0
type SimpleHandler struct { Handler http.HandlerFunc Path string Methods []string }
SimpleHandler represents a simplification to the standard http handlerFuncs, allowing simpler registration and logging with Routers.
type SimpleServer ¶ added in v1.0.1
type SimpleServer struct {
// contains filtered or unexported fields
}
SimpleServer represents an extension to the standard http.Server
func NewServerHTTP ¶ added in v1.0.0
func NewServerHTTP(Addr string) (*SimpleServer, error)
NewServerHTTP will create a new http.Server, with no TLS settings enabled. This will accept raw HTTP only.
func NewServerHTTPS ¶ added in v1.0.0
func NewServerHTTPS(TLS *TLSBundle, Addr string) (*SimpleServer, error)
NewServerHTTPS will create a new TLS-Enabled http.Server. This will
func (*SimpleServer) EnableAboutHandler ¶ added in v1.0.4
func (S *SimpleServer) EnableAboutHandler(r *mux.Router)
EnableAboutHandler will enable and set up the "about" handler, to display the available routes. This must be the last route registered in order for the full set of routes to be displayed.
func (*SimpleServer) ListenAndServe ¶ added in v1.0.1
func (S *SimpleServer) ListenAndServe() error
ListenAndServe will start the SimpleServer, serving HTTPS if enabled, or HTTP if not
func (*SimpleServer) RegisterRouter ¶ added in v1.0.1
func (S *SimpleServer) RegisterRouter(r http.Handler)
RegisterRouter will register the given Handler (typically an *http.ServeMux or *mux.Router) as the http Handler for the server.
func (*SimpleServer) Shutdown ¶ added in v1.0.1
func (S *SimpleServer) Shutdown()
Shutdown will safely shut down the SimpleServer, returning any errors