go-http-utils, v1.2
Posted on

The library that provides HTTP utility functions.
Adding the functions that work with JSON, the function to extract the parameter from the request URL path, and the improved analog of the http.Error() function.
Change Log
- analogs:
- adding an analog of the
http.Error()function with the additional improvements:- additional logging of the error;
- accepting of an error object instead of an error string;
- adding an analog of the
- adding the function to extract the parameter with the specified name from the path part of the request URL and then scan it into the data;
- JSON:
- adding the function to read bytes from the reader and then unmarshal them into the data;
- adding the function to marshal the data and then write it in the writer:
- additional setting of the corresponding content type;
- additional setting of the specified status code.
Features
- simplified interface of the
http.Clientstructure for mocking purposes; - wrapper for the
http.ResponseWriterinterface for catching writing errors; - middlewares:
- middleware for catching writing errors;
- middleware that fallback of requests to static assets to the index.html file (useful in a SPA);
- functions:
- analogs:
- analog of the
http.Redirect()function with catching writing errors; - analog of the
http.FileServer()function with applied above-mentioned middlewares; - analog of the
http.Error()function with the additional improvements:- additional logging of the error;
- accepting of an error object instead of an error string;
- analog of the
- function to extract the parameter with the specified name from the path part of the request URL and then scan it into the data;
- JSON:
- function to read bytes from the reader and then unmarshal them into the data;
- function to marshal the data and then write it in the writer:
- additional setting of the corresponding content type;
- additional setting of the specified status code;
- function to start a server with support for graceful shutdown by a signal.
- analogs:
Repository
Link: https://github.com/thewizardplusplus/go-http-utils/tree/v1.2.
Content: code.
License: MIT.