9cfe217997c3ec9e2ac4ebe8438cad596e22dc7c
[ealt-edge.git] / mep / mepagent / pkg / service / util.go
1 /*
2  *  Copyright 2020 Huawei Technologies Co., Ltd.
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 package service
18
19 import (
20         "gopkg.in/yaml.v2"
21         "io/ioutil"
22         "github.com/akraino-edge-stack/ealt-edge/mep/mepagent/pkg/model"
23 )
24
25 // get yaml and parse to struct
26 func GetConf(path string) (model.AppInstanceInfo, error) {
27         yamlFile, err := ioutil.ReadFile(path)
28         var info model.AppInstanceInfo
29         if err != nil {
30                 return info, err
31         }
32
33         err = yaml.UnmarshalStrict(yamlFile, &info)
34
35         if err != nil {
36                 return info, err
37         }
38
39         return info, nil
40 }
41
42 func GetAppConf(FilePath string) (model.AppConf, error) {
43         var AppInfo model.AppConf
44         yamlFile, err := ioutil.ReadFile(FilePath)
45         if err != nil {
46                 return AppInfo, err
47         }
48
49         err1 := yaml.UnmarshalStrict(yamlFile, &AppInfo)
50         if err1 != nil {
51                 return AppInfo, err
52         }
53
54         return AppInfo, nil
55
56 }