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/06/28 22:04:36 UTC

[GitHub] rob05c commented on a change in pull request #2475: Remove db from interface

rob05c commented on a change in pull request #2475: Remove db from interface
URL: https://github.com/apache/trafficcontrol/pull/2475#discussion_r198965218
 
 

 ##########
 File path: traffic_ops/traffic_ops_golang/api/shared_handlers.go
 ##########
 @@ -138,14 +140,55 @@ func ReadHandler(typeRef Reader, db *sqlx.DB) http.HandlerFunc {
 			return
 		}
 
-		user, err := auth.GetCurrentUser(ctx)
+		reader := typeFactory(inf)
+
+		results, errs, errType := reader.Read(params)
+		if len(errs) > 0 {
+			tc.HandleErrorsWithType(errs, errType, handleErrs)
+			return
+		}
+		resp := struct {
+			Response []interface{} `json:"response"`
+		}{results}
+
+		respBts, err := json.Marshal(resp)
 		if err != nil {
-			log.Errorf("unable to retrieve current user from context: %s", err)
 			handleErrs(http.StatusInternalServerError, err)
 			return
 		}
 
-		results, errs, errType := typeRef.Read(db, params, *user)
+		w.Header().Set("Content-Type", "application/json")
+		fmt.Fprintf(w, "%s", respBts)
+	}
+}
+
+//this creates a handler function from the pointer to a struct implementing the Reader interface
 
 Review comment:
   This will break Godoc, should start with the func name, `// ReadOnlyHandler creates...`

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