auth

Paddy 2015-01-29 Parent:d46d22e5b5d6 Child:cf6c1f05eb21

133:bc842183181d Go to Latest

auth/request.go

Add Client updating from the API. Add a handler to update Clients using the API. Add a helper that will decode a request for us based on its Content-Type header. Change the ClientChange.Validate function to return as many errors as possible, as opposed to just the first error it encounters. Update the ClientChange.Validate tests to take advantage of the new signature.

History
     1.1 --- a/request.go	Wed Jan 28 07:27:32 2015 -0500
     1.2 +++ b/request.go	Thu Jan 29 20:40:55 2015 -0500
     1.3 @@ -74,6 +74,18 @@
     1.4  	}
     1.5  }
     1.6  
     1.7 +func decode(r *http.Request, target interface{}) error {
     1.8 +	defer r.Body.Close()
     1.9 +	switch r.Header.Get("Content-Type") {
    1.10 +	case "application/json":
    1.11 +		dec := json.NewDecoder(r.Body)
    1.12 +		return dec.Decode(target)
    1.13 +	default:
    1.14 +		dec := json.NewDecoder(r.Body)
    1.15 +		return dec.Decode(target)
    1.16 +	}
    1.17 +}
    1.18 +
    1.19  func wrap(context Context, f func(w http.ResponseWriter, r *http.Request, context Context)) http.Handler {
    1.20  	return negotiate(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    1.21  		f(w, r, context)