mirror of
https://github.com/linka-cloud/grpc.git
synced 2025-06-22 17:22:26 +00:00
interceptors: add ban
health: set services serving on start and not available on close Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
34
interceptors/ban/context.go
Normal file
34
interceptors/ban/context.go
Normal file
@ -0,0 +1,34 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user