grpc/interceptors/ban/context.go
Adphi c7096975b1
interceptors: add ban
health: set services serving on start and not available on close

Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
2022-09-27 17:06:18 +02:00

35 lines
557 B
Go

package ban
import (
"context"
)
type key struct{}
type value struct {
ban *ban
actor string
done bool
}
func set(ctx context.Context, b *ban, actor string) context.Context {
return context.WithValue(ctx, key{}, &value{ban: b, actor: actor})
}
func Infraction(ctx context.Context, rule string) error {
v, ok := ctx.Value(key{}).(*value)
if !ok {
return nil
}
v.done = true
return v.ban.s.Infraction(v.actor, rule)
}
func Actor(ctx context.Context) string {
v, ok := ctx.Value(key{}).(*value)
if !ok {
return ""
}
return v.actor
}