/
identify.go
43 lines (36 loc) · 1.08 KB
/
identify.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
package utils
import (
"context"
)
// TLSKey is the key related to tls.
type TLSKey string
const (
// PouchTLSIssuer is the key of tls issue stored in context.
PouchTLSIssuer TLSKey = "pouch.server.tls.issuer"
// PouchTLSCommonName is the key of tls common name stored in context.
PouchTLSCommonName TLSKey = "pouch.server.tls.cn"
)
// SetTLSIssuer set issuer name of tls to context.
func SetTLSIssuer(ctx context.Context, issuer string) context.Context {
return context.WithValue(ctx, PouchTLSIssuer, issuer)
}
// GetTLSIssuer fetch issuer name from context.
func GetTLSIssuer(ctx context.Context) string {
issuer := ctx.Value(PouchTLSIssuer)
if issuer == nil {
return ""
}
return issuer.(string)
}
// SetTLSCommonName set common name of tls to context.
func SetTLSCommonName(ctx context.Context, cn string) context.Context {
return context.WithValue(ctx, PouchTLSCommonName, cn)
}
// GetTLSCommonName fetch common name from context.
func GetTLSCommonName(ctx context.Context) string {
issuer := ctx.Value(PouchTLSCommonName)
if issuer == nil {
return ""
}
return issuer.(string)
}