-
Notifications
You must be signed in to change notification settings - Fork 61
/
fakes.go
61 lines (43 loc) · 1.26 KB
/
fakes.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package reset
import (
"net/http"
"github.com/PacktPublishing/Hands-On-Dependency-Injection-in-Go/ch06/03_applying/05/data"
)
func notFoundHandler(response http.ResponseWriter, _ *http.Request) {
response.WriteHeader(http.StatusNotFound)
_, _ = response.Write([]byte(`Not found`))
}
// Fake/Stub implementations to make the compiler happy
type Server struct {
address string
handlerGet http.Handler
handlerList http.Handler
handlerNotFound http.HandlerFunc
handlerRegister http.Handler
}
func NewGetHandler(_ GetModel) *GetHandler {
return &GetHandler{}
}
type GetModel interface {
Do(ID int) (*data.Person, error)
}
type GetHandler struct{}
func (g *GetHandler) ServeHTTP(response http.ResponseWriter, request *http.Request) {}
func NewListHandler(_ ListModel) *ListHandler {
return &ListHandler{}
}
type ListModel interface {
Do() ([]*data.Person, error)
}
type ListHandler struct {
}
func (l *ListHandler) ServeHTTP(response http.ResponseWriter, request *http.Request) {}
func NewRegisterHandler(_ RegisterModel) *RegisterHandler {
return &RegisterHandler{}
}
type RegisterModel interface {
Do(in *data.Person) (int, error)
}
type RegisterHandler struct {
}
func (r *RegisterHandler) ServeHTTP(response http.ResponseWriter, request *http.Request) {}