Advanced Go is an exercise in creating a better way to write software, by extending REST from the service/HTTP layer to the application layer. The following goals are examined when applying REST to packages, error handling, URLs, and testing.
- Reduce complexity and toil
- Increase solution expressiveness
- Maximize reliability and resiliency
The uniform interface for a package simplifies the overall system architecture and increases the visibility of interactions. Expressiveness is enhanced in the following areas:
- Composition of packages - Supported via the uniform interface, and allows packages to be used as intermediaries for authorization, access logging, and request controllers for timeouts and routing.
- Microservice development - Packages are developed independently of hosts, allowing a package to exist in multiple hosts independent of cloud hosting architetures. Toil is reduced as packages are fully tested in development, not requiring additional service testing.
- Mobile Code Architectural Style - Packages are independent of services, providing a dynamic service topography where reliability and latency can be managed by combining packages in a single service.
A package also maintains the following REST constraints:
- Resource identifier - PkgPath
- Manipulation through representation - http.Request and http.Response
- Self descriptive message - http.Request and http.Response
The error handler uniform interface simplifies development and reduces toil by allowing an application to determine where an error is handled via a generic error handler type.
Expressiveness is achieved via different error handler implementations for different environments and/or use cases such as error logging, echoing errors to stdout, or bypassing error handling.
Treating a URL as a resource, where manipulation of the URL is through a representation, allows for that representation to change over time as an application migrates through different development environments. A resolver type, provides different representations of a URL and is the mechanism used to resolve URLs for testing, using the file scheme, (file://) and other environments using the HTTP or HTTPS scheme (http://,https://). Runtime configurable templates, used during URL resolution, provide the necessary expresiveness. The use of a uniform type provides simplicity and reduces toil by performing URL resolution with one type, instead of formatting embedded URL strings.
Testing utilizes a package's uniform interface to test all requests and related responses. The requests and responses are HTTP text files, deserialized from disk into the appropriate http.Request and http.Response types. This allows an automated, reliable, easy to extend solution for testing. Since the HttpHandler is the public interface for the package, no further testing of the package needs to be done in a service.