OpenID Connect (OIDC) identity and OAuth 2.0 provider with pluggable connectors
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

31 lines
619 B

package simplehttp
import (
"encoding/json"
"net/http"
)
func GetJSONInput(r *http.Request, w http.ResponseWriter, v interface{}) (err error) {
decoder := json.NewDecoder(r.Body)
err = decoder.Decode(v)
if err != nil {
http.Error(w, "Bad request.", http.StatusBadRequest)
return err
}
return nil
}
func OutputJSON(w http.ResponseWriter, v interface{}) (err error) {
var data []byte
data, err = json.Marshal(v)
if err != nil {
http.Error(w, "Internal error.", http.StatusInternalServerError)
return err
}
w.Header().Add("Content-Type", "application/json")
_, err = w.Write(data)
return nil
}