-
Notifications
You must be signed in to change notification settings - Fork 1
/
01_long_param.go
66 lines (54 loc) · 1.4 KB
/
01_long_param.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
62
63
64
65
66
package long_param
import (
"net/http"
"time"
)
func NewMyHandler(logger Logger, stats Instrumentation,
parser Parser, formatter Formatter,
limiter RateLimiter,
cache Cache, db Datastore) *MyHandler {
return &MyHandler{
// code removed
}
}
// MyHandler does something fantastic
type MyHandler struct {
// code removed
}
func (m *MyHandler) ServeHTTP(response http.ResponseWriter, request *http.Request) {
// code removed
}
// Logger logs stuff
type Logger interface {
Error(message string, args ...interface{})
Warn(message string, args ...interface{})
Info(message string, args ...interface{})
Debug(message string, args ...interface{})
}
// Instrumentation records the performances and events
type Instrumentation interface {
Count(key string, value int)
Duration(key string, start time.Time)
}
// Parse will extract details from the request
type Parser interface {
Extract(req *http.Request) (int, error)
}
// Formatter will build the output
type Formatter interface {
Format(resp http.ResponseWriter, data []byte) error
}
// RateLimiter limits how many concurrent requests we can make or process
type RateLimiter interface {
Acquire()
Release()
}
// Datastore will store/retrieve data in a permanent
type Datastore interface {
Load(ID int) ([]byte, error)
}
// Cache will store/retrieve data in a fast way
type Cache interface {
Store(key string, data []byte)
Get(key string) ([]byte, error)
}