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 { type memory struct {
sync.RWMutex
records map[string]services records map[string]services
watchers map[string]*watcher watchers map[string]*watcher
opts Options opts Options
sync.RWMutex
} }
// services is a KV map with service name as the key and a map of records as the value // 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 // Resolver is a DNS network resolve
type Resolver struct { type Resolver struct {
goresolver *net.Resolver
// Address of resolver to use
Address string
sync.RWMutex sync.RWMutex
goresolver *net.Resolver
Address string
} }
// Resolve tries to resolve endpoint address // Resolve tries to resolve endpoint address
@ -47,7 +46,7 @@ func (r *Resolver) Resolve(name string) ([]*resolver.Record, error) {
if goresolver == nil { if goresolver == nil {
r.Lock() r.Lock()
r.goresolver = &net.Resolver{ 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{ d := net.Dialer{
Timeout: time.Millisecond * time.Duration(100), Timeout: time.Millisecond * time.Duration(100),
} }

View File

@ -36,11 +36,11 @@ type handler struct {
type subscriber struct { type subscriber struct {
typ reflect.Type typ reflect.Type
subscriber interface{} subscriber interface{}
rcvr reflect.Value
topic string topic string
endpoints []*register.Endpoint endpoints []*register.Endpoint
handlers []*handler handlers []*handler
opts SubscriberOptions opts SubscriberOptions
rcvr reflect.Value
} }
// Is this an exported - upper case - name? // 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 { type service struct {
opts Options
sync.RWMutex sync.RWMutex
// once sync.Once opts Options
} }
// NewService creates and returns a new Service based on the packages within. // 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 { if err = cfg.Init(config.Context(cfg.Options().Context)); err != nil {
return err return err
} }
if err = cfg.Load(cfg.Options().Context); err != nil {
return err
}
} }
for _, log := range s.opts.Loggers { for _, log := range s.opts.Loggers {

View File

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

View File

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

View File

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

View File

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