package condition import ( "git.fsdpf.net/go/reflux/valuex" "git.fsdpf.net/go/req" ) type TokenValue interface { GetParam(k string) valuex.Accessor User() req.User } type tValueOpt func(option *tValue) func WithUser(user req.User) tValueOpt { return func(option *tValue) { option.user = user } } func NewTokenValue(x valuex.Accessor, opts ...tValueOpt) TokenValue { tv := &tValue{src: x} if x == nil { tv.src = valuex.Nil } else if up, ok := x.(interface{ User() req.User }); ok { tv.user = up.User() } for _, opt := range opts { if opt != nil { opt(tv) } } if tv.user == nil { panic("user is required") } return tv } type tValue struct { src valuex.Accessor user req.User } func (this *tValue) GetParam(k string) valuex.Accessor { if v, ok := this.src.Lookup(k); ok { return v } return valuex.Nil } func (this *tValue) User() req.User { return this.user }