Initial commit
[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 package main
17
18 import (
19     "fmt"
20     "./sdl"
21 )
22
23 func main() {
24     sdl1 := sdl.Create("test1")
25
26     var err error
27
28     err = sdl1.Set("key1", "data1", "key2", "data2")
29     if err != nil {
30         fmt.Printf("unable to write to DB\n")
31     }
32
33     err = sdl1.Set("num1", 1, "num2", 2)
34     if err != nil {
35         fmt.Printf("unable to write to DB\n")
36     }
37
38     d := make([]byte, 3)
39     d[0] = 1
40     d[1] = 2
41     d[2] = 3
42     err = sdl1.Set("arr1", d)
43     if err != nil {
44         fmt.Printf("unable to write to DB\n")
45     }
46
47     p := []string{"pair1", "data1", "pair2", "data2"}
48     err = sdl1.Set(p)
49     if err != nil {
50         fmt.Printf("unable to write to DB\n")
51     }
52
53     a := [4]string{"array1", "adata1", "array2", "adata2"}
54     err = sdl1.Set(a)
55     if err != nil {
56         fmt.Printf("unable to write to DB\n")
57     }
58
59     mix1 := []interface{}{"mix1", "data1", "mix2", 2}
60     err = sdl1.Set(mix1)
61     if err != nil {
62         fmt.Printf("unable to write to DB\n")
63     }
64
65     mix2 := [4]interface{}{"mix3", "data3", "mix4", 4}
66     err = sdl1.Set(mix2)
67     if err != nil {
68         fmt.Printf("unable to write to DB\n")
69     }
70
71     retDataMap, err := sdl1.Get([]string{"key1", "key3", "key2"})
72     if err != nil {
73         fmt.Printf("Unable to read from DB\n")
74     } else {
75         for i, v := range retDataMap {
76             fmt.Printf("%s:%s\n", i, v)
77         }
78     }
79
80     retDataMap2, err := sdl1.Get([]string{"num1", "num2"})
81     if err != nil {
82         fmt.Printf("Unable to read from DB\n")
83     } else {
84         for i, v := range retDataMap2 {
85             fmt.Printf("%s:%s\n", i, v)
86         }
87     }
88
89     fmt.Println("-------------")
90     allKeys := []string{"key1", "key2", "num1", "num2", "pair1", "pair2", "array1", "array2", "mix1", "mix2", "mix3", "mix4", "arr1"}
91     retDataMap3, err := sdl1.Get(allKeys)
92     if err != nil {
93         fmt.Printf("Unable to read from DB\n")
94     } else {
95         for i3, v3 := range retDataMap3 {
96             fmt.Printf("%s:%s\n", i3, v3)
97         }
98     }
99 }