From 1e2706a383a7b494004989e9a1bc2095d4a5fb5a Mon Sep 17 00:00:00 2001 From: wsfuyibing Date: Mon, 28 Oct 2024 18:11:31 +0800 Subject: [PATCH] debug for mul-dsn --- db/src/service.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/db/src/service.go b/db/src/service.go index 80781d2..ff632a1 100644 --- a/db/src/service.go +++ b/db/src/service.go @@ -16,44 +16,44 @@ package src import ( - "context" + "context" ) // Service // is a top level component used to operate database. type Service struct { - key string - session *Session + key string + session *Session } // Master // returns a shared master session of a connection. func (o *Service) Master(ctx context.Context) (*Session, error) { - if o.session != nil { - return o.session, nil - } - return Config.GetMaster(ctx) + if o.session != nil { + return o.session, nil + } + return Config.GetMaster(ctx, o.key) } // Slave // returns a shared slave session of a connection. func (o *Service) Slave(ctx context.Context) (*Session, error) { - if o.session != nil { - return o.session, nil - } - return Config.GetSlave(ctx) + if o.session != nil { + return o.session, nil + } + return Config.GetSlave(ctx, o.key) } // With // set a shared session of a connection on a service. func (o *Service) With(sessions ...*Session) { - if len(sessions) > 0 && sessions[0] != nil { - o.session = sessions[0] - } + if len(sessions) > 0 && sessions[0] != nil { + o.session = sessions[0] + } } // WithKey // specify a connection key in your mapping. func (o *Service) WithKey(key string) { - o.key = key + o.key = key } -- Gitee