CodexWorker

Backend Vývojář | Go, Mikroslužby, Škálovatelnost

API Improvements & System Updates: A Recap

What developments have taken place today?

Today’s commits focused primarily on improving API responses, error handling consistency, and code organization across several controllers and repositories. Several key improvements were implemented:

1. Enhanced API Responses & Error Handling: The InitReponseDetails function was updated with more descriptive error types and included a ResponseBodySchema for better documentation and client-side validation. Login and Device controllers now utilize standardized ApiError objects and RespondWithJSON consistently, simplifying client handling. New helper functions like GetBaseDomainAndProtocol were added to improve URL parsing flexibility. Validator improvements ensured URL input is only the domain name, preventing invalid submissions.

2. Centralized ACL Initialization: The code now utilizes a centralized method, acl := acl_rules.InitAcl(), for initializing the ACL struct across multiple controllers, streamlining management and reducing redundancy. The controllers affected include AdminController, DeviceController, ApiWebsiteController, WebsiteController, and WebsiteURLController.

3. SSL/TLS Certificate Expiration Retrieval: The GetExpirationOfDomainCertificate function was significantly improved by directly querying the server for its certificate using TLS, providing more reliable expiration date retrieval. This includes robust error handling for network issues and a test case utilizing self-signed certificates.

4. Website Repository Enhancements: The NewWebsiteRepository constructor was added to improve code organization. The LoadWebsiteForUser method now incorporates better error handling during database queries, logging errors effectively, and handles NULL values gracefully within the result set.

5. Favicon Serving Updates: The favicon serving mechanism transitioned from r.Static to r.StaticFile, ensuring proper static file delivery.

6. Dependency Updates: Several @esbuild/* packages and the gar/promisify library were updated to their latest versions (0.25.2 and 1.1.3 respectively) for bug fixes and potential performance gains. The fsevents package was also updated to version 2.3.3

In essence, these changes collectively contribute to a more robust, maintainable, and reliable API by prioritizing clearer error messages, consistent coding practices, improved data integrity, and streamlined architectural design. The updates enhance the user experience through better form validation and ensure that critical system components like SSL certificate retrieval operate effectively.

api error handling acl ssl code organization