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/05/22 20:36:23 UTC

[GitHub] rawlinp commented on a change in pull request #2247: Add an Origin API

rawlinp commented on a change in pull request #2247: Add an Origin API
URL: https://github.com/apache/incubator-trafficcontrol/pull/2247#discussion_r190044166
 
 

 ##########
 File path: lib/go-tc/v13/origins.go
 ##########
 @@ -0,0 +1,150 @@
+package v13
+
+import (
+	"github.com/apache/incubator-trafficcontrol/lib/go-tc"
+)
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+type OriginsResponse struct {
+	Response []OriginNullable `json:"response"`
+}
+
+// OriginDetailResponse is the JSON object returned for a single origin
+type OriginDetailResponse struct {
+	Response OriginNullable `json:"response"`
+	tc.Alerts
+}
+
+type Origin struct {
+	Cachegroup        string       `json:"cachegroup" db:"cachegroup"`
+	CachegroupID      int          `json:"cachegroupId" db:"cachegroup_id"`
+	Coordinate        string       `json:"coordinate" db:"coordinate"`
+	CoordinateID      int          `json:"coordinateId" db:"coordinate_id"`
+	DeliveryService   string       `json:"deliveryService" db:"deliveryservice"`
+	DeliveryServiceID int          `json:"deliveryServiceId" db:"deliveryservice_id"`
+	FQDN              string       `json:"fqdn" db:"fqdn"`
+	ID                int          `json:"id" db:"id"`
+	IP6Address        string       `json:"ip6Address" db:"ip6_address"`
+	IPAddress         string       `json:"ipAddress" db:"ip_address"`
+	IsPrimary         bool         `json:"isPrimary" db:"is_primary"`
+	LastUpdated       tc.TimeNoMod `json:"lastUpdated" db:"last_updated"`
+	Name              string       `json:"name" db:"name"`
+	Port              int          `json:"port" db:"port"`
+	Profile           string       `json:"profile" db:"profile"`
+	ProfileID         int          `json:"profileId" db:"profile_id"`
+	Protocol          string       `json:"protocol" db:"protocol"`
+	Tenant            string       `json:"tenant" db:"tenant"`
+	TenantID          int          `json:"tenantId" db:"tenant_id"`
+}
+
+type OriginNullable struct {
+	Cachegroup        *string       `json:"cachegroup" db:"cachegroup"`
+	CachegroupID      *int          `json:"cachegroupId" db:"cachegroup_id"`
+	Coordinate        *string       `json:"coordinate" db:"coordinate"`
+	CoordinateID      *int          `json:"coordinateId" db:"coordinate_id"`
+	DeliveryService   *string       `json:"deliveryService" db:"deliveryservice"`
+	DeliveryServiceID *int          `json:"deliveryServiceId" db:"deliveryservice_id"`
+	FQDN              *string       `json:"fqdn" db:"fqdn"`
+	ID                *int          `json:"id" db:"id"`
+	IP6Address        *string       `json:"ip6Address" db:"ip6_address"`
+	IPAddress         *string       `json:"ipAddress" db:"ip_address"`
+	IsPrimary         *bool         `json:"isPrimary" db:"is_primary"`
+	LastUpdated       *tc.TimeNoMod `json:"lastUpdated" db:"last_updated"`
+	Name              *string       `json:"name" db:"name"`
+	Port              *int          `json:"port" db:"port"`
+	Profile           *string       `json:"profile" db:"profile"`
+	ProfileID         *int          `json:"profileId" db:"profile_id"`
+	Protocol          *string       `json:"protocol" db:"protocol"`
+	Tenant            *string       `json:"tenant" db:"tenant"`
+	TenantID          *int          `json:"tenantId" db:"tenant_id"`
+}
+
+type OriginBuilder struct {
 
 Review comment:
   Yeah they're not currently used anywhere in the codebase, but I found it useful when I was implementing a test program using the Origin client. Since none of the other client implementations use the `*Nullable` structs yet, something like this hasn't really been necessary. Without it, you basically have to declare a temporary variable and `&` that variable when setting the pointer in the `*Nullable` struct. Using this Builder pattern you basically just:
   ```
   foo := NewOriginBuilder().CacheGroupID(1).CoordinateID(1).Build()
   ```
   as opposed to:
   ```
   cgID := 1
   coordID := 1
   foo := OriginNullable{CachegroupID: &cgID, CoordinateID: &coordID}
   ```

----------------------------------------------------------------
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