mirror of
https://github.com/linka-cloud/grpc.git
synced 2024-11-05 10:46:25 +00:00
Adphi
c7096975b1
health: set services serving on start and not available on close Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
35 lines
557 B
Go
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
|
|
}
|