Debian Codegraph @

context.go

raw
1 //go:build go1.7
2 // +build go1.7
3
4 package csrf
5
6 import (
7 "context"
8 "fmt"
9 "net/http"
10 )
11
12 func contextGet(r *http.Request, key string) (interface{}, error) {
13 val := r.Context().Value(key)
14 if val == nil {
15 return nil, fmt.Errorf("no value exists in the context for key %q", key)
16 }
17 return val, nil
18 }
19
20 func contextSave(r *http.Request, key string, val interface{}) *http.Request {
21 ctx := r.Context()
22 ctx = context.WithValue(ctx, key, val) // nolint:staticcheck
23 return r.WithContext(ctx)
24 }
25
26 func contextClear(r *http.Request) {
27 // no-op for go1.7+
28 }