Merge pull request #110 from unistack-org/config

service: config load only on start, not init phase
This commit is contained in:
Василий Толстов 2022-03-30 15:39:51 +03:00 committed by GitHub
commit 226ec43ecf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 11 additions and 18 deletions

View File

@ -29,10 +29,10 @@ type record struct {
}
type memory struct {
sync.RWMutex
records map[string]services
watchers map[string]*watcher
opts Options
sync.RWMutex
}
// services is a KV map with service name as the key and a map of records as the value

View File

@ -12,10 +12,9 @@ import (
// Resolver is a DNS network resolve
type Resolver struct {
goresolver *net.Resolver
// Address of resolver to use
Address string
sync.RWMutex
goresolver *net.Resolver
Address string
}
// Resolve tries to resolve endpoint address
@ -47,7 +46,7 @@ func (r *Resolver) Resolve(name string) ([]*resolver.Record, error) {
if goresolver == nil {
r.Lock()
r.goresolver = &net.Resolver{
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
Dial: func(ctx context.Context, _ string, _ string) (net.Conn, error) {
d := net.Dialer{
Timeout: time.Millisecond * time.Duration(100),
}

View File

@ -36,11 +36,11 @@ type handler struct {
type subscriber struct {
typ reflect.Type
subscriber interface{}
rcvr reflect.Value
topic string
endpoints []*register.Endpoint
handlers []*handler
opts SubscriberOptions
rcvr reflect.Value
}
// Is this an exported - upper case - name?

View File

@ -73,9 +73,8 @@ func RegisterSubscriber(topic string, s server.Server, h interface{}, opts ...se
}
type service struct {
opts Options
sync.RWMutex
// once sync.Once
opts Options
}
// NewService creates and returns a new Service based on the packages within.
@ -108,11 +107,6 @@ func (s *service) Init(opts ...Option) error {
if err = cfg.Init(config.Context(cfg.Options().Context)); err != nil {
return err
}
if err = cfg.Load(cfg.Options().Context); err != nil {
return err
}
}
for _, log := range s.opts.Loggers {

View File

@ -6,9 +6,9 @@ import (
)
type memorySync struct {
mtx gosync.RWMutex
locks map[string]*memoryLock
options Options
mtx gosync.RWMutex
}
type memoryLock struct {

View File

@ -10,16 +10,16 @@ import (
// Buffer is ring buffer
type Buffer struct {
sync.RWMutex
streams map[string]*Stream
vals []*Entry
size int
sync.RWMutex
}
// Entry is ring buffer data entry
type Entry struct {
Value interface{}
Timestamp time.Time
Value interface{}
}
// Stream is used to stream the buffer

View File

@ -6,8 +6,8 @@ import (
// Pool holds the socket pool
type Pool struct {
pool map[string]*Socket
sync.RWMutex
pool map[string]*Socket
}
// Get socket from pool

View File

@ -20,10 +20,10 @@ type Stream interface {
}
type stream struct {
sync.RWMutex
Stream
err error
request *request
sync.RWMutex
}
type request struct {