Cleanup
This commit is contained in:
@@ -65,13 +65,26 @@ func (app *App) handleSignedIn(pattern string, fn handlerFunc) {
|
||||
})
|
||||
}
|
||||
|
||||
type peerHandlerFunc func(w http.ResponseWriter, r *http.Request) error
|
||||
type peerHandlerFunc func(p *api.Peer, w http.ResponseWriter, r *http.Request) error
|
||||
|
||||
func (app *App) handlePeer(pattern string, fn peerHandlerFunc) {
|
||||
wrapped := func(w http.ResponseWriter, r *http.Request) {
|
||||
_, apiKey, ok := r.BasicAuth()
|
||||
if !ok {
|
||||
http.Error(w, "Not authorized", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
peer, err := app.api.Peer_GetByAPIKey(apiKey)
|
||||
if err != nil {
|
||||
http.Error(w, "Not authorized", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
r.ParseForm()
|
||||
if err := fn(w, r); err != nil {
|
||||
if err := fn(peer, w, r); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user