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 2019/10/08 21:54:19 UTC
[GitHub] [trafficcontrol] rob05c commented on a change in pull request
#3966: Add server capabilities API
rob05c commented on a change in pull request #3966: Add server capabilities API
URL: https://github.com/apache/trafficcontrol/pull/3966#discussion_r332723725
##########
File path: traffic_ops/traffic_ops_golang/servercapability/servercapability.go
##########
@@ -0,0 +1,100 @@
+package servercapability
+
+/*
+ * 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.
+ */
+
+import (
+ "github.com/apache/trafficcontrol/lib/go-tc"
+ "github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
+ "github.com/apache/trafficcontrol/lib/go-util"
+ "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api"
+ "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers"
+
+ validation "github.com/go-ozzo/ozzo-validation"
+)
+
+type TOServerCapability struct {
+ api.APIInfoImpl `json:"-"`
+ tc.ServerCapability
+}
+
+func (v *TOServerCapability) SetLastUpdated(t tc.TimeNoMod) { v.LastUpdated = &t }
+func (v *TOServerCapability) InsertQuery() string { return insertQuery() }
+func (v *TOServerCapability) NewReadObj() interface{} { return &tc.ServerCapability{} }
+func (v *TOServerCapability) SelectQuery() string { return selectQuery() }
+func (v *TOServerCapability) ParamColumns() map[string]dbhelpers.WhereColumnInfo {
+ return map[string]dbhelpers.WhereColumnInfo{
+ "name": {"sc.name", nil},
+ }
+}
+func (v *TOServerCapability) DeleteQuery() string { return deleteQuery() }
+
+func (v TOServerCapability) GetKeyFieldsInfo() []api.KeyFieldInfo {
+ return []api.KeyFieldInfo{{"name", api.GetStringKey}}
+}
+
+//Implementation of the Identifier, Validator interface functions
+func (v TOServerCapability) GetKeys() (map[string]interface{}, bool) {
+ return map[string]interface{}{"name": v.Name}, true
+}
+
+func (v *TOServerCapability) SetKeys(keys map[string]interface{}) {
+ v.Name, _ = keys["name"].(string)
+}
+
+func (v *TOServerCapability) GetAuditName() string {
+ return v.Name
+}
+
+func (v *TOServerCapability) GetType() string {
+ return "server capability"
+}
+
+func (v *TOServerCapability) Validate() error {
+ errs := validation.Errors{
+ "name": validation.Validate(v.Name, validation.Required),
+ }
+ return util.JoinErrs(tovalidate.ToErrors(errs))
+}
+
+func (v *TOServerCapability) Read() ([]interface{}, error, error, int) { return api.GenericRead(v) }
+func (v *TOServerCapability) Create() (error, error, int) { return api.GenericCreateNameBasedID(v) }
+func (v *TOServerCapability) Delete() (error, error, int) { return api.GenericDelete(v) }
+
+func selectQuery() string {
+ return `SELECT
+name,
+last_updated
+FROM server_capability sc`
+}
+
+func insertQuery() string {
+ query := `INSERT INTO server_capability (
+name
+) VALUES (
+:name
+) RETURNING last_updated`
+ return query
+}
+
+func deleteQuery() string {
+ query := `DELETE FROM server_capability
+WHERE name=:name`
+ return query
+}
Review comment:
+1 on "return `DELETE"
In fact, I wouldn't even call the separate func an "idiom," I'd be +1 on putting the whole thing directly in `TOServerCapability.DeleteQuery`.
But that's really a nitpick, I wouldn't hold the review up for it.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services