ocket8888 commented on code in PR #7213:
URL: https://github.com/apache/trafficcontrol/pull/7213#discussion_r1047331960
##########
traffic_ops/traffic_ops_golang/servercapability/servercapability.go:
##########
@@ -151,6 +153,147 @@ func (v *TOServerCapability) Update(h http.Header)
(error, error, int) {
return nil, nil, http.StatusOK
}
+func GetServerCapability(w http.ResponseWriter, r *http.Request) {
+ var sc tc.ServerCapabilityV4
+ inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+ tx := inf.Tx
+ if userErr != nil || sysErr != nil {
+ api.HandleErr(w, r, tx.Tx, errCode, userErr, sysErr)
+ return
+ }
+ defer inf.Close()
+
+ // Query Parameters to Database Query column mappings
+ queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+ "name": {Column: "sc.name", Checker: nil},
+ }
+ if _, ok := inf.Params["orderby"]; !ok {
+ inf.Params["orderby"] = "name"
+ }
+ where, orderBy, pagination, queryValues, errs :=
dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params, queryParamsToQueryCols)
+ if len(errs) > 0 {
+ api.HandleErr(w, r, tx.Tx, http.StatusBadRequest,
util.JoinErrs(errs), nil)
+ return
+ }
+
+ const selectQuery = "SELECT name, description, last_updated FROM
server_capability sc"
+ query := selectQuery + where + orderBy + pagination
+ rows, err := tx.Query(query, queryValues)
+ if err != nil {
+ api.HandleErr(w, r, tx.Tx, http.StatusInternalServerError, nil,
fmt.Errorf("server capability read: error getting server capability(ies): %w",
err))
+ }
+ defer log.Close(rows, "unable to close DB connection")
+
+ scList := []tc.ServerCapabilityV4{}
+ for rows.Next() {
+ if err = rows.Scan(&sc.Name, &sc.Description, &sc.LastUpdated);
err != nil {
+ api.HandleErr(w, r, tx.Tx,
http.StatusInternalServerError, nil, fmt.Errorf("error getting server
capability(ies): %w", err))
+ }
+ scList = append(scList, sc)
+ }
+
+ api.WriteResp(w, r, scList)
+ return
Review Comment:
According to codecov, this final `return` is not hit by the tests. That plus
the invalid JSON error in the client tests leads me to believe that a scan
error is occurring that hits line 190, probably multiple times which may or may
not be causing a panic. It needs a `return` statement so that execution stops
when an error is handled.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]