-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathinstance.go
56 lines (46 loc) · 1.59 KB
/
instance.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
package http
import (
"context"
"net/http"
)
// Handler is a function instance which can handle a request.
//
// This is of course specific to Go functions, with other languages using types
// of their own (see language-specific runtime middleware), but the conceptual
// framework is the same.
type Handler interface {
// Handle a request.
Handle(http.ResponseWriter, *http.Request)
}
type HandleFunc func(http.ResponseWriter, *http.Request)
// Starter is an instance which has defined the Start hook
type Starter interface {
// Start instance event hook.
Start(context.Context, map[string]string) error
}
// Stopper is an instance which has defined the Stop hook
type Stopper interface {
// Stop instance event hook.
Stop(context.Context) error
}
// ReadinessReporter is an instance which reports its readiness.
type ReadinessReporter interface {
// Ready to be invoked or not.
Ready(context.Context) (bool, error)
}
// LivenessReporter is an instance which reports it is alive.
type LivenessReporter interface {
// Alive allows the instance to report it's liveness status.
Alive(context.Context) (bool, error)
}
// DefaultHandler is used for simple static function implementations which
// need only define a single exported function named Handle of type HandleFunc.
type DefaultHandler struct {
// TODO: Update type HandleFunc when backwards compatibility no
// longer needed:
Handler handleFuncDeprecated
}
func (f DefaultHandler) Handle(w http.ResponseWriter, r *http.Request) {
f.Handler(r.Context(), w, r)
}
type handleFuncDeprecated func(context.Context, http.ResponseWriter, *http.Request)