| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 | package routerimport (	"context"	"sync")type Router interface {	Pick(ctx context.Context) (string, bool)}type defaultRouter bytefunc (defaultRouter) Pick(ctx context.Context) (string, bool) {	return "", false}type syncRouter struct {	sync.RWMutex	Router}func (r *syncRouter) Pick(ctx context.Context) (string, bool) {	r.RLock()	defer r.RUnlock()	return r.Router.Pick(ctx)}func (r *syncRouter) Set(router Router) {	r.Lock()	defer r.Unlock()	r.Router = router}var (	routerInstance = &syncRouter{		Router: defaultRouter(0),	})func RegisterRouter(router Router) {	if router == nil {		panic("Router is nil.")	}	routerInstance.Set(router)}func Pick(ctx context.Context) (string, bool) {	return routerInstance.Router.Pick(ctx)}
 |