first commit. Way too late.
This commit is contained in:
commit
da7cacb57e
35 files changed
+1355
No files matched your search
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type errorWrapper struct {
|
||||
Error error `json:"error"`
|
||||
}
|
||||
|
||||
type ApiHandler func(w http.ResponseWriter, request *http.Request) (interface{}, error)
|
||||
|
||||
func (this ApiHandler) ServeHTTP(w http.ResponseWriter, request *http.Request) {
|
||||
ret, err := this(w, request)
|
||||
if err != nil {
|
||||
ret = &errorWrapper{err}
|
||||
w.WriteHeader(500)
|
||||
} else {
|
||||
w.WriteHeader(200)
|
||||
}
|
||||
enc := json.NewEncoder(w)
|
||||
enc.Encode(ret)
|
||||
}
|
||||
Reference in new issue
Block a user