-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
herodot.go
33 lines (22 loc) · 876 Bytes
/
herodot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package herodot
import (
"net/http"
"github.com/pborman/uuid"
"golang.org/x/net/context"
)
type key int
const RequestIDKey key = 0
func NewContext() context.Context {
ctx := context.Background()
return context.WithValue(ctx, RequestIDKey, uuid.New())
}
func Context(ctx context.Context) context.Context {
return context.WithValue(ctx, RequestIDKey, uuid.New())
}
type Herodot interface {
Write(ctx context.Context, w http.ResponseWriter, r *http.Request, e interface{})
WriteCode(ctx context.Context, w http.ResponseWriter, r *http.Request, code int, e interface{})
WriteCreated(ctx context.Context, w http.ResponseWriter, r *http.Request, location string, e interface{})
WriteError(ctx context.Context, w http.ResponseWriter, r *http.Request, err error)
WriteErrorCode(ctx context.Context, w http.ResponseWriter, r *http.Request, code int, err error)
}