ee39cb862c58c4c96b495ef1c103072ee9347c4c
[ric-plt/dbaas.git] / testapplication / go / testapp.go
1 //   Copyright (c) 2019 AT&T Intellectual Property.
2 //   Copyright (c) 2019 Nokia.
3 //
4 //   Licensed under the Apache License, Version 2.0 (the "License");
5 //   you may not use this file except in compliance with the License.
6 //   You may obtain a copy of the License at
7 //
8 //       http://www.apache.org/licenses/LICENSE-2.0
9 //
10 //   Unless required by applicable law or agreed to in writing, software
11 //   distributed under the License is distributed on an "AS IS" BASIS,
12 //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 //   See the License for the specific language governing permissions and
14 //   limitations under the License.
15
16 //
17 //   This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 //   platform project (RICP).
19 //
20
21 package main
22
23 import (
24     "fmt"
25     "./sdl"
26 )
27
28 func main() {
29     sdl1 := sdl.Create("test1")
30
31     var err error
32
33     err = sdl1.Set("key1", "data1", "key2", "data2")
34     if err != nil {
35         fmt.Printf("unable to write to DB\n")
36     }
37
38     err = sdl1.Set("num1", 1, "num2", 2)
39     if err != nil {
40         fmt.Printf("unable to write to DB\n")
41     }
42
43     d := make([]byte, 3)
44     d[0] = 1
45     d[1] = 2
46     d[2] = 3
47     err = sdl1.Set("arr1", d)
48     if err != nil {
49         fmt.Printf("unable to write to DB\n")
50     }
51
52     p := []string{"pair1", "data1", "pair2", "data2"}
53     err = sdl1.Set(p)
54     if err != nil {
55         fmt.Printf("unable to write to DB\n")
56     }
57
58     a := [4]string{"array1", "adata1", "array2", "adata2"}
59     err = sdl1.Set(a)
60     if err != nil {
61         fmt.Printf("unable to write to DB\n")
62     }
63
64     mix1 := []interface{}{"mix1", "data1", "mix2", 2}
65     err = sdl1.Set(mix1)
66     if err != nil {
67         fmt.Printf("unable to write to DB\n")
68     }
69
70     mix2 := [4]interface{}{"mix3", "data3", "mix4", 4}
71     err = sdl1.Set(mix2)
72     if err != nil {
73         fmt.Printf("unable to write to DB\n")
74     }
75
76     retDataMap, err := sdl1.Get([]string{"key1", "key3", "key2"})
77     if err != nil {
78         fmt.Printf("Unable to read from DB\n")
79     } else {
80         for i, v := range retDataMap {
81             fmt.Printf("%s:%s\n", i, v)
82         }
83     }
84
85     retDataMap2, err := sdl1.Get([]string{"num1", "num2"})
86     if err != nil {
87         fmt.Printf("Unable to read from DB\n")
88     } else {
89         for i, v := range retDataMap2 {
90             fmt.Printf("%s:%s\n", i, v)
91         }
92     }
93
94     fmt.Println("-------------")
95     allKeys := []string{"key1", "key2", "num1", "num2", "pair1", "pair2", "array1", "array2", "mix1", "mix2", "mix3", "mix4", "arr1"}
96     retDataMap3, err := sdl1.Get(allKeys)
97     if err != nil {
98         fmt.Printf("Unable to read from DB\n")
99     } else {
100         for i3, v3 := range retDataMap3 {
101             fmt.Printf("%s:%s\n", i3, v3)
102         }
103     }
104 }