VOL-1900 lint warning fixes db
Change-Id: Iaa4e5c271c9e1d7c8ebce1e13c7e723ea4762304
diff --git a/db/model/non_persisted_revision.go b/db/model/non_persisted_revision.go
index c7fb6ea..b796217 100644
--- a/db/model/non_persisted_revision.go
+++ b/db/model/non_persisted_revision.go
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package model
import (
@@ -20,14 +21,15 @@
"context"
"crypto/md5"
"fmt"
- "github.com/golang/protobuf/proto"
- "github.com/opencord/voltha-lib-go/v2/pkg/db/kvstore"
- "github.com/opencord/voltha-lib-go/v2/pkg/log"
"reflect"
"sort"
"strings"
"sync"
"time"
+
+ "github.com/golang/protobuf/proto"
+ "github.com/opencord/voltha-lib-go/v2/pkg/db/kvstore"
+ "github.com/opencord/voltha-lib-go/v2/pkg/log"
)
// TODO: Cache logic will have to be revisited to cleanup unused entries in memory (disabled for now)
@@ -50,13 +52,14 @@
var revCacheInstance *revCacheSingleton
var revCacheOnce sync.Once
-func GetRevCache() *revCacheSingleton {
+func getRevCache() *revCacheSingleton {
revCacheOnce.Do(func() {
revCacheInstance = &revCacheSingleton{Cache: sync.Map{}}
})
return revCacheInstance
}
+// NonPersistedRevision -
type NonPersistedRevision struct {
mutex sync.RWMutex
Root *root
@@ -70,6 +73,7 @@
lastUpdate time.Time
}
+// NewNonPersistedRevision -
func NewNonPersistedRevision(root *root, branch *Branch, data interface{}, children map[string][]Revision) Revision {
r := &NonPersistedRevision{}
r.Root = root
@@ -80,18 +84,21 @@
return r
}
+// SetConfig -
func (npr *NonPersistedRevision) SetConfig(config *DataRevision) {
npr.mutex.Lock()
defer npr.mutex.Unlock()
npr.Config = config
}
+// GetConfig -
func (npr *NonPersistedRevision) GetConfig() *DataRevision {
npr.mutex.Lock()
defer npr.mutex.Unlock()
return npr.Config
}
+// SetAllChildren -
func (npr *NonPersistedRevision) SetAllChildren(children map[string][]Revision) {
npr.childrenLock.Lock()
defer npr.childrenLock.Unlock()
@@ -103,6 +110,7 @@
}
}
+// SetChildren -
func (npr *NonPersistedRevision) SetChildren(name string, children []Revision) {
npr.childrenLock.Lock()
defer npr.childrenLock.Unlock()
@@ -111,6 +119,7 @@
copy(npr.Children[name], children)
}
+// GetAllChildren -
func (npr *NonPersistedRevision) GetAllChildren() map[string][]Revision {
npr.childrenLock.Lock()
defer npr.childrenLock.Unlock()
@@ -118,6 +127,7 @@
return npr.Children
}
+// GetChildren -
func (npr *NonPersistedRevision) GetChildren(name string) []Revision {
npr.childrenLock.Lock()
defer npr.childrenLock.Unlock()
@@ -128,47 +138,56 @@
return nil
}
+// SetHash -
func (npr *NonPersistedRevision) SetHash(hash string) {
npr.mutex.Lock()
defer npr.mutex.Unlock()
npr.Hash = hash
}
+// GetHash -
func (npr *NonPersistedRevision) GetHash() string {
//npr.mutex.Lock()
//defer npr.mutex.Unlock()
return npr.Hash
}
+// ClearHash -
func (npr *NonPersistedRevision) ClearHash() {
npr.mutex.Lock()
defer npr.mutex.Unlock()
npr.Hash = ""
}
+// GetName -
func (npr *NonPersistedRevision) GetName() string {
//npr.mutex.Lock()
//defer npr.mutex.Unlock()
return npr.Name
}
+// SetName -
func (npr *NonPersistedRevision) SetName(name string) {
//npr.mutex.Lock()
//defer npr.mutex.Unlock()
npr.Name = name
}
+
+// SetBranch -
func (npr *NonPersistedRevision) SetBranch(branch *Branch) {
npr.mutex.Lock()
defer npr.mutex.Unlock()
npr.Branch = branch
}
+// GetBranch -
func (npr *NonPersistedRevision) GetBranch() *Branch {
npr.mutex.Lock()
defer npr.mutex.Unlock()
return npr.Branch
}
+// GetData -
func (npr *NonPersistedRevision) GetData() interface{} {
npr.mutex.Lock()
defer npr.mutex.Unlock()
@@ -178,12 +197,13 @@
return npr.Config.Data
}
-func (npr *NonPersistedRevision) GetNode() *node {
+func (npr *NonPersistedRevision) getNode() *node {
npr.mutex.Lock()
defer npr.mutex.Unlock()
return npr.Branch.Node
}
+// Finalize -
func (npr *NonPersistedRevision) Finalize(skipOnExist bool) {
npr.Hash = npr.hashContent()
}
@@ -243,8 +263,8 @@
childData := rev.Get(depth - 1)
foundEntry := false
for i := 0; i < childDataHolder.Len(); i++ {
- cdh_if := childDataHolder.Index(i).Interface()
- if cdh_if.(proto.Message).String() == childData.(proto.Message).String() {
+ cdhIf := childDataHolder.Index(i).Interface()
+ if cdhIf.(proto.Message).String() == childData.(proto.Message).String() {
foundEntry = true
break
}
@@ -255,7 +275,7 @@
}
}
} else {
- if revs := npr.GetBranch().GetLatest().GetChildren(fieldName); revs != nil && len(revs) > 0 {
+ if revs := npr.GetBranch().GetLatest().GetChildren(fieldName); len(revs) > 0 {
rev := revs[0]
if rev != nil {
childData := rev.Get(depth - 1)
@@ -374,7 +394,7 @@
})
// replace entry
- newChild.GetNode().SetRoot(existingChildren[nameIndex].GetNode().GetRoot())
+ newChild.getNode().SetRoot(existingChildren[nameIndex].getNode().GetRoot())
updatedChildren = append(updatedChildren, newChild)
} else {
log.Debugw("keeping-existing-child", log.Fields{
@@ -459,7 +479,7 @@
}
}
-/// ChildDropByName will remove a child entry matching the type and name
+// ChildDropByName will remove a child entry matching the type and name
func (npr *NonPersistedRevision) ChildDropByName(childName string) {
// Extract device type
parts := strings.SplitN(childName, "/", 2)
@@ -478,17 +498,19 @@
}
}
+// SetLastUpdate -
func (npr *NonPersistedRevision) SetLastUpdate(ts ...time.Time) {
npr.mutex.Lock()
defer npr.mutex.Unlock()
- if ts != nil && len(ts) > 0 {
+ if len(ts) > 0 {
npr.lastUpdate = ts[0]
} else {
npr.lastUpdate = time.Now()
}
}
+// GetLastUpdate -
func (npr *NonPersistedRevision) GetLastUpdate() time.Time {
npr.mutex.RLock()
defer npr.mutex.RUnlock()
@@ -501,10 +523,12 @@
return nil, nil
}
+// SetupWatch -
func (npr *NonPersistedRevision) SetupWatch(key string) {
// stub ... required by interface
}
+// StorageDrop -
func (npr *NonPersistedRevision) StorageDrop(txid string, includeConfig bool) {
// stub ... required by interface
}