mirror of
https://github.com/linka-cloud/grpc.git
synced 2024-11-24 11:56:26 +00:00
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
|
||
|
}
|