Update openssl package of DBAAS docker image
[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         "testapp/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         _, err = sdl1.SetIf("key1", "data1", "data2")
77         if err != nil {
78                 fmt.Printf("unable to write to DB\n")
79         }
80
81         retDataMap, err := sdl1.Get([]string{"key1", "key3", "key2"})
82         if err != nil {
83                 fmt.Printf("Unable to read from DB\n")
84         } else {
85                 for i, v := range retDataMap {
86                         fmt.Printf("%s:%s\n", i, v)
87                 }
88         }
89
90         retDataMap2, err := sdl1.Get([]string{"num1", "num2"})
91         if err != nil {
92                 fmt.Printf("Unable to read from DB\n")
93         } else {
94                 for i, v := range retDataMap2 {
95                         fmt.Printf("%s:%s\n", i, v)
96                 }
97         }
98
99         fmt.Println("-------------")
100         allKeys := []string{"key1", "key2", "num1", "num2", "pair1", "pair2", "array1", "array2", "mix1", "mix2", "mix3", "mix4", "arr1"}
101         retDataMap3, err := sdl1.Get(allKeys)
102         if err != nil {
103                 fmt.Printf("Unable to read from DB\n")
104         } else {
105                 for i3, v3 := range retDataMap3 {
106                         fmt.Printf("%s:%s\n", i3, v3)
107                 }
108         }
109 }