From 383f28faeb81a2a5d5fa5462cba2ff6c9cce5154 Mon Sep 17 00:00:00 2001 From: Cluas Date: Wed, 9 Nov 2022 17:36:36 +0800 Subject: [PATCH] fix(selector): set global do not work (#2489) * fix(selector): set global do not work * fix(selector): test * fix(selector): return early * fix(selector): use struct * fix(selector): use struct --- selector/global.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/selector/global.go b/selector/global.go index 2f951212b..4d6b6202c 100644 --- a/selector/global.go +++ b/selector/global.go @@ -1,13 +1,21 @@ package selector -var globalSelector Builder +var globalSelector = &wrapSelector{} + +var _ Builder = (*wrapSelector)(nil) + +// wrapSelector wrapped Selector, help override global Selector implementation. +type wrapSelector struct{ Builder } // GlobalSelector returns global selector builder. func GlobalSelector() Builder { - return globalSelector + if globalSelector.Builder != nil { + return globalSelector + } + return nil } // SetGlobalSelector set global selector builder. func SetGlobalSelector(builder Builder) { - globalSelector = builder + globalSelector.Builder = builder }