Seed code for Routing Manager (ric-plt/rtmgr).
[ric-plt/rtmgr.git] / pkg / nbi / httpgetter.go
1 /*
2 ==================================================================================
3   Copyright (c) 2019 AT&T Intellectual Property.
4   Copyright (c) 2019 Nokia
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17 ==================================================================================
18 */
19 /*
20   Mnemonic:     httpgetter.go
21   Abstract:     HTTPgetter NBI implementation
22                 Simple HTTP getter solution. Only for testing purpose.
23   Date:         15 March 2019
24 */
25
26 package nbi
27
28 import (
29         "encoding/json"
30         "net/http"
31         "rtmgr"
32         "time"
33 )
34
35 var myClient = &http.Client{Timeout: 1 * time.Second}
36
37 func fetchXappList(url string) (*[]rtmgr.XApp, error) {
38         rtmgr.Logger.Debug("Invoked httpgetter.fetchXappList")
39         r, err := myClient.Get(url)
40         if err != nil {
41                 return nil, err
42         }
43         defer r.Body.Close()
44         rtmgr.Logger.Debug("http client raw response: %v", r)
45         var xapps []rtmgr.XApp
46         json.NewDecoder(r.Body).Decode(&xapps)
47         rtmgr.Logger.Info("HTTP GET: OK")
48         rtmgr.Logger.Debug("httpgetter.fetchXappList returns: %v", xapps)
49         return &xapps, err
50 }