close #1560

This fixes one of the reported data races and also allows for
having a different name on the micro.Service and web.Service.
This makes it possible to discover the two service variants separately.

Co-authored-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Patrik Lindahl 2020-05-19 19:11:26 +08:00 committed by GitHub
parent 3d36398818
commit f0c0f3d4c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -112,8 +112,8 @@ func (s *service) run(exit chan bool) {
} }
func (s *service) register() error { func (s *service) register() error {
s.RLock() s.Lock()
defer s.RUnlock() defer s.Unlock()
if s.srv == nil { if s.srv == nil {
return nil return nil
@ -142,8 +142,8 @@ func (s *service) register() error {
} }
func (s *service) deregister() error { func (s *service) deregister() error {
s.RLock() s.Lock()
defer s.RUnlock() defer s.Unlock()
if s.srv == nil { if s.srv == nil {
return nil return nil
@ -406,7 +406,9 @@ func (s *service) Init(opts ...Option) error {
s.RLock() s.RLock()
// pass in own name and version // pass in own name and version
serviceOpts = append(serviceOpts, micro.Name(s.opts.Name)) if s.opts.Service.Name() == "" {
serviceOpts = append(serviceOpts, micro.Name(s.opts.Name))
}
serviceOpts = append(serviceOpts, micro.Version(s.opts.Version)) serviceOpts = append(serviceOpts, micro.Version(s.opts.Version))
s.RUnlock() s.RUnlock()