fix golint issues in core/syncx (#526)
This commit is contained in:
@@ -7,12 +7,14 @@ import (
|
||||
"github.com/tal-tech/go-zero/core/errorx"
|
||||
)
|
||||
|
||||
// A ResourceManager is a manager that used to manage resources.
|
||||
type ResourceManager struct {
|
||||
resources map[string]io.Closer
|
||||
sharedCalls SharedCalls
|
||||
lock sync.RWMutex
|
||||
}
|
||||
|
||||
// NewResourceManager returns a ResourceManager.
|
||||
func NewResourceManager() *ResourceManager {
|
||||
return &ResourceManager{
|
||||
resources: make(map[string]io.Closer),
|
||||
@@ -20,6 +22,7 @@ func NewResourceManager() *ResourceManager {
|
||||
}
|
||||
}
|
||||
|
||||
// Close closes the manager.
|
||||
func (manager *ResourceManager) Close() error {
|
||||
manager.lock.Lock()
|
||||
defer manager.lock.Unlock()
|
||||
@@ -34,6 +37,7 @@ func (manager *ResourceManager) Close() error {
|
||||
return be.Err()
|
||||
}
|
||||
|
||||
// GetResource returns the resource associated with given key.
|
||||
func (manager *ResourceManager) GetResource(key string, create func() (io.Closer, error)) (io.Closer, error) {
|
||||
val, err := manager.sharedCalls.Do(key, func() (interface{}, error) {
|
||||
manager.lock.RLock()
|
||||
|
||||
Reference in New Issue
Block a user