// RequestAuth checks if the authorization is still valid before actually request
// user authorization
RequestAuth checks if the authorization is still valid before actually request
user authorization
// RequestAuth checks if the authorization is still valid before actually request // user authorization
func (m *AuthorizationManager) RequestAuth(
	req *AuthRequest,
	permitDuration *time.Duration,
	penaltyDuration *time.Duration,
) error {
	target := timeoutDataKey{
		authReqKey: req.CreateKey(m.policy),
	}
	_, ok := m.penaltyTQ.Find(target)
	if ok {
		return fmt.Errorf("penalty duration not ended")
	}
	_, ok = m.permitTQ.Find(target)
	if ok {
		return nil
	}
	err := m.handler.Authorize(req)
	if err != nil {
		dur := m.defaultPenaltyDuration
		if penaltyDuration != nil {
			dur = *penaltyDuration
		}
		_ = m.penaltyTQ.OfferWithDelay(target, struct{}{}, dur)
		return err
	}
	dur := m.defaultPermitDuration
	if permitDuration != nil {
		dur = *permitDuration
	}
	return m.permitTQ.OfferWithDelay(
		target, &timeoutDataValue{}, dur,
	)
}
func ( m * AuthorizationManager ) RequestAuth ( req * AuthRequest , permitDuration * time . Duration , penaltyDuration * time . Duration , ) error { target := timeoutDataKey { authReqKey : req . CreateKey ( m . policy ) , } _ , ok := m . penaltyTQ . Find ( target ) if ok { return fmt . Errorf ( " " ) } _ , ok = m . permitTQ . Find ( target ) if ok { return nil } err := m . handler . Authorize ( req ) if err != nil { dur := m . defaultPenaltyDuration if penaltyDuration != nil { dur = * penaltyDuration } _ = m . penaltyTQ . OfferWithDelay ( target , struct { } { } , dur ) return err } dur := m . defaultPermitDuration if permitDuration != nil { dur = * permitDuration } return m . permitTQ . OfferWithDelay ( target , & timeoutDataValue { } , dur , ) }
RequestAuth checks if the authorization is still valid before actually request
user authorization
RequestAuth checks if the authorization is still valid before actually request user authorization
// check whether failed before // check whether have allowed this request before // this request is new, do actual auth request