Github user rob05c commented on a diff in the pull request:

    
https://github.com/apache/incubator-trafficcontrol/pull/325#discussion_r107811947
  
    --- Diff: traffic_ops/experimental/go-api/tenant/EndPointSeeder.go ---
    @@ -0,0 +1,202 @@
    +package tenant
    +
    +/*
    + 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.
    +*/
    +
    + 
    +import (
    +    "database/sql"
    +    "encoding/json"
    +    "net/http"
    +    "fmt"
    +    "time"
    +
    +    "github.com/gorilla/mux"
    +  _ "github.com/lib/pq"
    +)
    +
    +
    +//TODO(nirs) polymorphisem
    +
    +/////BASE - COMMON TO ALL SEEDERS (needs to move to another package)
    +/// Defintions
    +type EndpointSeeder struct{
    +    myDb        *sql.DB
    +}
    +
    +/// Interface
    +func NewEndpointSeeder(aDb *sql.DB) *EndpointSeeder {
    +    endPointSeeder := new(EndpointSeeder)
    +    endPointSeeder.myDb = aDb
    +    return endPointSeeder
    +}
    +
    +func (aEndpointSeeder *EndpointSeeder) Seed (aRouter *mux.Router, 
aApiPrefix string) {
    +
    +    aRouter.HandleFunc(aApiPrefix+"/tenants", 
aEndpointSeeder.getListEndpoint).Methods("GET")
    +    aRouter.HandleFunc(aApiPrefix+"/tenants/{id}", 
aEndpointSeeder.getEndpoint).Methods("GET")
    +    aRouter.HandleFunc(aApiPrefix+"/tenants", 
aEndpointSeeder.createEndpoint).Methods("POST")
    +    aRouter.HandleFunc(aApiPrefix+"/tenants/{id}", 
aEndpointSeeder.updateEndpoint).Methods("PUT")
    +    aRouter.HandleFunc(aApiPrefix+"/tenants/{id}", 
aEndpointSeeder.deleteEndpoint).Methods("DELETE")
    +}
    +
    +///Common utilities
    +func (aEndpointSeeder *EndpointSeeder) checkErr(aError error) {
    +    //TODO log
    +    if aError != nil {
    +        panic(aError)
    --- End diff --
    
    A `panic` call is not acceptable in production code. It violates flow 
control, and further it crashes the application. Here, `checkErr` is called for 
errors from client requests, so clients can potentially crash the application 
with a bad request.
    
    A function like `checkErr` is acceptable for logging, but not panicing. 
Code calling `checkErr` should be refactored to return an error up the stack, 
until an appropriate caller, some initial HTTP handler func in this case, can 
log the error and return gracefully.
    
    When you're changing this to pass errors up, the preferred technique is for 
every function to add context via `fmt.Errorf`. E.g. ```if err := 
processJson(); err {
      return fmt.Errorf("error processing JSON: %v", err)
    }```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to