mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
add caller infor to write response msg
This commit is contained in:
parent
dd9b69a9bd
commit
51c8f648e5
@ -1,6 +1,9 @@
|
|||||||
package databag
|
package databag
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"log"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"errors"
|
"errors"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -12,7 +15,9 @@ import (
|
|||||||
func WriteResponse(w http.ResponseWriter, v interface{}) {
|
func WriteResponse(w http.ResponseWriter, v interface{}) {
|
||||||
body, err := json.Marshal(v);
|
body, err := json.Marshal(v);
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LogMsg("marshal failed")
|
_, file, line, _ := runtime.Caller(1)
|
||||||
|
p, _ := os.Getwd()
|
||||||
|
log.Printf("%s:%d %s", strings.TrimPrefix(file, p), line, err.Error())
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
} else {
|
} else {
|
||||||
w.Write(body);
|
w.Write(body);
|
||||||
|
Loading…
Reference in New Issue
Block a user