File size: 418 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package csp

import (
	"context"
)

type nonceval struct{}

// WithNonce will add a nonce value to the context.
func WithNonce(ctx context.Context, value string) context.Context {
	return context.WithValue(ctx, nonceval{}, value)
}

// NonceValue will return the nonce value from the context.
func NonceValue(ctx context.Context) string {
	v := ctx.Value(nonceval{})
	if v == nil {
		return ""
	}
	return v.(string)
}