kdamichie commented on code in PR #7605: URL: https://github.com/apache/trafficcontrol/pull/7605#discussion_r1281001597
########## traffic_ops/traffic_ops_golang/cachegroup/cachegroups.go: ########## @@ -897,3 +955,483 @@ last_updated` func DeleteQuery() string { return `DELETE FROM cachegroup WHERE id=$1` } + +// Get [Version : V5] function Process the *http.Request and writes the response. It uses GetCacheGroup function. +func Get(w http.ResponseWriter, r *http.Request) { + inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil) + if userErr != nil || sysErr != nil { + api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr) + return + } + defer inf.Close() + + code := http.StatusOK + useIMS := false + config, e := api.GetConfig(r.Context()) + if e == nil && config != nil { + useIMS = config.UseIMS + } else { + log.Warnf("Couldn't get config %v", e) + } + + var maxTime time.Time + var usrErr error + var syErr error + + var cgList []interface{} + + tx := inf.Tx + + cgList, maxTime, code, usrErr, syErr = GetCacheGroup(tx, inf.Params, useIMS, r.Header) + if code == http.StatusNotModified { + w.WriteHeader(code) + api.WriteResp(w, r, []tc.CacheGroupV5{}) + return + } + + if code == http.StatusBadRequest { + api.HandleErr(w, r, inf.Tx.Tx, http.StatusBadRequest, usrErr, nil) + return + } + + if sysErr != nil { + api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, syErr) + return + } + + if maxTime != (time.Time{}) && api.SetLastModifiedHeader(r, useIMS) { + api.AddLastModifiedHdr(w, maxTime) + } + + api.WriteResp(w, r, cgList) +} + +// GetCacheGroup [Version : V5] receives transactions from Get function and returns cache groups list. +func GetCacheGroup(tx *sqlx.Tx, params map[string]string, useIMS bool, header http.Header) ([]interface{}, time.Time, int, error, error) { + //func GetCacheGroup(tx *sqlx.Tx, params map[string]string, useIMS bool, header http.Header) ([]tc.CacheGroupV5, time.Time, int, error, error) { Review Comment: done -- 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: issues-unsubscr...@trafficcontrol.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org