1package hcsshim
2
3import (
4	"encoding/json"
5	"fmt"
6
7	"github.com/sirupsen/logrus"
8)
9
10func hnsCall(method, path, request string, returnResponse interface{}) error {
11	var responseBuffer *uint16
12	logrus.Debugf("[%s]=>[%s] Request : %s", method, path, request)
13
14	err := _hnsCall(method, path, request, &responseBuffer)
15	if err != nil {
16		return makeError(err, "hnsCall ", "")
17	}
18	response := convertAndFreeCoTaskMemString(responseBuffer)
19
20	hnsresponse := &hnsResponse{}
21	if err = json.Unmarshal([]byte(response), &hnsresponse); err != nil {
22		return err
23	}
24
25	if !hnsresponse.Success {
26		return fmt.Errorf("HNS failed with error : %s", hnsresponse.Error)
27	}
28
29	if len(hnsresponse.Output) == 0 {
30		return nil
31	}
32
33	logrus.Debugf("Network Response : %s", hnsresponse.Output)
34	err = json.Unmarshal(hnsresponse.Output, returnResponse)
35	if err != nil {
36		return err
37	}
38
39	return nil
40}
41