4 ms·
This is cool but I think its brittle against real world scenarios: func (r *Resource) get(w http.ResponseWriter, r *http.Request){ user, err := r.a
by ben_jones 8y ago
This is cool but I think its brittle against real world scenarios:
func (r *Resource) get(w http.ResponseWriter, r *http.Request){
user, err := r.authenticate(req)
if err != nil {
r.WriteJSONErr(w, err)
return
}
var records []*User
if err := r.db.Select("select id, name, created_date from users", &records); err != nil {
r.WriteJSONErr(w, err)
return
}
r.WriteJSON(w, records)
}
You would have to reformat all your function signatures to receive maybe a pointer to populate and return only an error, which could work but meh.
- johan_larson 8y agoYes, the pattern isn't useful for function calls that return results that are used as parameters in later function calls, which tends to happen all the time.
- userbinator 8y agoIt works as long as the return value can be used to distinguish failure from success: (f = fopen(filename, "rb")) && ... (ptr = malloc(size)) && fread(ptr, 1, size, f) == size && ...
- latchkey 8y agoReal world scenario? I would have wrapped this in a custom http.HandlerFunc that did the authentication portion... similar to this (obviously not showing the auth portion, but setting headers)... https://github.com/blockassets/bam_agent/blob/master/tool/http.go https://github.com/blockassets/bam_agent/blob/master/tool/ht...
- deleted 8y ago[deleted]