You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2021/05/24 13:30:38 UTC

[GitHub] [trafficcontrol] ocket8888 opened a new pull request #5880: Api info reorganization

ocket8888 opened a new pull request #5880:
URL: https://github.com/apache/trafficcontrol/pull/5880


   ## What does this PR (Pull Request) do?
   - [x] This PR is not related to any Issue
   
   This PR restructures the familiar `api.APIInfo` struct a bit. It retains a reference to an http response writer, allowing many `api` package functions to be aliased with a much shorter argument list.
   
   For example,
   
   ```go
   api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
   ```
   
   can be called as simply
   ```go
   inf.HandleErr(errCode, userErr, sysErr)
   ```
   
   ... allowing you to pass only the information that has actually changed since the handler function's execution began.
   
   New methods include aliases for response writing, some IMS/IUS/IM niceties, parsing/parse-and-validating, and a handler for parsing and writing db errors in the same step, which converts
   
   ```go
   if err := dbOperation(); err != nil {
       userErr, sysErr, errCode := api.ParseDBError(err)
       api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
       return
   }
   ```
   into
   ```go
   if err := dbOperation(); err != nil {
       inf.HandleDBErr(err)
       return
   }
   ```
   
   This also changes the info struct's name from `api.APIInfo` to `api.Info` (because the former "stutters"), moves it and its methods to its own file, and changes the `Version` member from a reference to an `api.Version` to just an `api.Version` value. Apart from naming, call signature (now requires the response writer to construct) and that one field change, most code is untouched. However, the `/acme_accounts` handlers have been retooled to showcase the new Info methods, and part of the DSRs handler was also done to show off an IMS-related method (because `/acme_accounts` does not support IMS requests).
   
   Also, this PR removed the deprecated `/lib/go-tc.GetHandleErrorsFunc` and the last three places it was used.
   
   ## Which Traffic Control components are affected by this PR?
   - Traffic Ops
   
   ## What is the best way to verify this PR?
   Make sure unit and client/TO integration tests still pass.
   
   ## The following criteria are ALL met by this PR
   - [x] This PR includes tests
   - [x] Documentation is unnecessary, because the changes only affect internal development.
   - [x] An update to CHANGELOG.md is not necessary because client-facing behavior is unaltered.
   - [x] This PR includes any and all required license headers
   - [x] This PR **DOES NOT FIX A SERIOUS SECURITY VULNERABILITY**


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org