X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=internal%2Fcli%2Ftypes.go;h=4b50964b71b2ce91a6d13e0c7f488e8b7f8a21fd;hb=refs%2Fchanges%2F50%2F9150%2F1;hp=de99e623b52cfa265001a6372ea2a29f983f5bec;hpb=977a55ca96d5dba1c7f9273671747eaf9cd6f894;p=ric-plt%2Fsdlgo.git diff --git a/internal/cli/types.go b/internal/cli/types.go index de99e62..4b50964 100644 --- a/internal/cli/types.go +++ b/internal/cli/types.go @@ -22,13 +22,19 @@ package cli -import "gerrit.o-ran-sc.org/r/ric-plt/sdlgo/internal/sdlgoredis" +import ( + "fmt" + "gerrit.o-ran-sc.org/r/ric-plt/sdlgo/internal/sdlgoredis" + "strings" +) //iDatabase is an interface towards database backend, for the time being //sdlgoredis.DB implements this interface. type iDatabase interface { Info() (*sdlgoredis.DbInfo, error) State() (*sdlgoredis.DbState, error) + Keys(pattern string) ([]string, error) + Statistics() (*sdlgoredis.DbStatistics, error) } //Database struct is a holder for the internal database instances. @@ -39,5 +45,44 @@ type Database struct { //DbCreateCb callback function type to create a new database type DbCreateCb func() *Database +//iSyncStorage is an interface towards SDL SyncStorage API +type ISyncStorage interface { + Get(ns string, keys []string) (map[string]interface{}, error) + ListKeys(ns string, pattern string) ([]string, error) + Set(ns string, pairs ...interface{}) error + Remove(ns string, keys []string) error +} + +//SyncStorageCreateCb callback function type to create a new SyncStorageInterface +type SyncStorageCreateCb func() ISyncStorage + +//keysArgs struct is used for keys command arguments. +type keysArgs struct { + ns string + pattern string +} + +//NewKeysArgs constructs a new keysArgs struct. +func NewKeysArgs(ns string, pattern string) keysArgs { + return keysArgs{ + ns: ns, + pattern: pattern, + } +} + +//Validate command arguments in keysArgs. +func (k keysArgs) Validate() error { + if strings.Contains(k.ns, "*") { + return fmt.Errorf("Invalid character (*) in given %s namespace argument.", k.ns) + } + return nil +} + +//nsMap is a map having SDL DB cluster address as a key and namespace map of type nsKeyMap as a value +type nsMap map[string]nsKeyMap + +//nsKeyMap is a map having namespace as a key and DB key count as a value +type nsKeyMap map[string]uint32 + //SdlCliApp constant defines the name of the SDL CLI application const SdlCliApp = "sdlcli"