ezelkow1 commented on a change in pull request #3075: Traffic Ops Golang 
parent.config
URL: https://github.com/apache/trafficcontrol/pull/3075#discussion_r240396553
 
 

 ##########
 File path: traffic_ops/client/atsconfig.go
 ##########
 @@ -0,0 +1,91 @@
+/*
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+
+package client
+
+import (
+       "encoding/json"
+       "io/ioutil"
+       "net/http"
+       "strconv"
+
+       "github.com/apache/trafficcontrol/lib/go-tc"
+)
+
+func (to *Session) GetATSServerConfigList(serverID int) (tc.ATSConfigMetaData, 
ReqInf, error) {
+       resp, remoteAddr, err := to.request(http.MethodGet, 
apiBase+"/servers/"+strconv.Itoa(serverID)+"/configfiles/ats", nil)
+       reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: 
remoteAddr}
+       if err != nil {
+               return tc.ATSConfigMetaData{}, reqInf, err
+       }
+       defer resp.Body.Close()
+
+       data := tc.ATSConfigMetaData{}
+       if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
+               return tc.ATSConfigMetaData{}, reqInf, err
+       }
+       return data, reqInf, nil
+}
+
+func (to *Session) GetATSServerConfigListByName(serverHostName string) 
(tc.ATSConfigMetaData, ReqInf, error) {
+       resp, remoteAddr, err := to.request(http.MethodGet, 
apiBase+"/servers/"+serverHostName+"/configfiles/ats", nil)
+       reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: 
remoteAddr}
+       if err != nil {
+               return tc.ATSConfigMetaData{}, reqInf, err
+       }
+       defer resp.Body.Close()
+
+       data := tc.ATSConfigMetaData{}
+       if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
+               return tc.ATSConfigMetaData{}, reqInf, err
+       }
+       return data, reqInf, nil
+}
+
+func (to *Session) GetATSServerConfig(serverID int, fileName string) (string, 
ReqInf, error) {
+       return to.getConfigFile(apiBase + "/servers/" + strconv.Itoa(serverID) 
+ "/configfiles/ats/" + fileName)
+}
+
+func (to *Session) GetATSServerConfigByName(serverHostName string, fileName 
string) (string, ReqInf, error) {
+       return to.getConfigFile(apiBase + "/servers/" + serverHostName + 
"/configfiles/ats/" + fileName)
+}
+
+func (to *Session) GetATSProfileConfig(profileID int, fileName string) 
(string, ReqInf, error) {
+       return to.getConfigFile(apiBase + "/profiles/" + 
strconv.Itoa(profileID) + "/configfiles/ats/" + fileName)
+}
+
+func (to *Session) GetATSProfileConfigByName(profileName string, fileName 
string) (string, ReqInf, error) {
+       return to.getConfigFile(apiBase + "/profiles/" + profileName + 
"/configfiles/ats/" + fileName)
+}
+
+func (to *Session) GetATSCDNConfig(cdnID int, fileName string) (string, 
ReqInf, error) {
+       return to.getConfigFile(apiBase + "/cdns/" + strconv.Itoa(cdnID) + 
"/configfiles/ats/" + fileName)
+}
+
+func (to *Session) GetATSCDNConfigByName(cdnName string, fileName string) 
(string, ReqInf, error) {
+       return to.getConfigFile(apiBase + "/cdns/" + cdnName + 
"/configfiles/ats/" + fileName)
+}
+
+func (to *Session) getConfigFile(uri string) (string, ReqInf, error) {
+       resp, remoteAddr, err := to.request(http.MethodGet, uri, nil)
+       reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr: 
remoteAddr}
+       if err != nil {
 
 Review comment:
   maybe need to move this up? Otherwise you are using remoteAddr before the 
err check

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to