/
codec.go
37 lines (30 loc) · 922 Bytes
/
codec.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
34
35
36
37
package autoroute
import (
"errors"
"net/http"
"reflect"
)
var (
ErrTooManyInputArgs = errors.New("autoroute: a function can only have up to three input args")
ErrTooManyOutputArgs = errors.New("autoroute: a function can only have up to two output args")
)
// A Codec implements pluggable, mime-type based serialization and deserialization
// for autoroute based Handlers
type Codec interface {
Mime() string
ValidFn(fn reflect.Value) error
HandleRequest(*CodecRequestArgs)
}
// CodecRequestArgs is passed to a Codec when it matches the mime type
// of a given request
type CodecRequestArgs struct {
ResponseWriter http.ResponseWriter
Request *http.Request
ErrorHandler ErrorHandler
Header Header
// Our nice bit of reflection stuff to work with
HandlerFn reflect.Value
HandlerType reflect.Type
InputArgCount, OutputArgCount int
MaxSizeBytes int64
}