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 2018/12/10 22:11:27 UTC

[GitHub] rob05c commented on a change in pull request #3075: Traffic Ops Golang parent.config

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

 ##########
 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:
   It's ok, this is how `remoteAddr` works. `to.request` is specifically defined to return a nil-or-valid `remoteAddr` even if `err != nil`. 
   
   It's a violation of the Go idiom that "if a non-nil err is returned, all other returned values are undefined", but there's no simple way to avoid it, without ugly and awkward Error types and typecasting.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services