-
Notifications
You must be signed in to change notification settings - Fork 2
/
noops.go
36 lines (27 loc) · 780 Bytes
/
noops.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
package autohttp
import (
"errors"
"io"
"net/http"
"reflect"
)
type NoOpDecoder struct{}
func (noop NoOpDecoder) ValidateType(fn interface{}) error {
if reflect.ValueOf(fn).Type().NumIn() != 0 {
return errors.New("noop decoder only works for functions with no inputs")
}
return nil
}
func (noop NoOpDecoder) Decode(fn interface{}, r *http.Request) ([]reflect.Value, error) {
return nil, nil
}
type NoOpEncoder struct{}
func (noop NoOpEncoder) ValidateType(fn interface{}) error {
if reflect.ValueOf(fn).Type().NumOut() != 0 {
return errors.New("noop encoder only works for functions with no return values")
}
return nil
}
func (noop NoOpEncoder) Encode(value interface{}, hw HeaderWriter) (int, io.Reader, error) {
return http.StatusNoContent, nil, nil
}