-
Notifications
You must be signed in to change notification settings - Fork 328
/
handlers_storage_session.go
42 lines (34 loc) · 1.03 KB
/
handlers_storage_session.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
package handlers
import (
"net/http"
"github.com/rexray/rexray/libstorage/api/context"
"github.com/rexray/rexray/libstorage/api/types"
)
// storageSessionHandler is an HTTP filter for ensuring that a storage session
// is injected for routes that request it.
type storageSessionHandler struct {
handler types.APIFunc
}
// NewStorageSessionHandler returns a new filter for ensuring that a storage
// session is injected for routes that request it.
func NewStorageSessionHandler() types.Middleware {
return &storageSessionHandler{}
}
func (h *storageSessionHandler) Name() string {
return "storage-session-handler"
}
func (h *storageSessionHandler) Handler(m types.APIFunc) types.APIFunc {
return (&storageSessionHandler{m}).Handle
}
// Handle is the type's Handler function.
func (h *storageSessionHandler) Handle(
ctx types.Context,
w http.ResponseWriter,
req *http.Request,
store types.Store) error {
var err error
if ctx, err = context.WithStorageSession(ctx); err != nil {
return err
}
return h.handler(ctx, w, req, store)
}