...

Source file src/github.com/Microsoft/hcsshim/internal/hns/hnsfuncs.go

Documentation: github.com/Microsoft/hcsshim/internal/hns

     1  //go:build windows
     2  
     3  package hns
     4  
     5  import (
     6  	"encoding/json"
     7  	"fmt"
     8  
     9  	"github.com/Microsoft/hcsshim/internal/hcserror"
    10  	"github.com/Microsoft/hcsshim/internal/interop"
    11  	"github.com/sirupsen/logrus"
    12  )
    13  
    14  func hnsCallRawResponse(method, path, request string) (*hnsResponse, error) {
    15  	var responseBuffer *uint16
    16  	logrus.Debugf("[%s]=>[%s] Request : %s", method, path, request)
    17  
    18  	err := _hnsCall(method, path, request, &responseBuffer)
    19  	if err != nil {
    20  		return nil, hcserror.New(err, "hnsCall ", "")
    21  	}
    22  	response := interop.ConvertAndFreeCoTaskMemString(responseBuffer)
    23  
    24  	hnsresponse := &hnsResponse{}
    25  	if err = json.Unmarshal([]byte(response), &hnsresponse); err != nil {
    26  		return nil, err
    27  	}
    28  	return hnsresponse, nil
    29  }
    30  
    31  func hnsCall(method, path, request string, returnResponse interface{}) error {
    32  	hnsresponse, err := hnsCallRawResponse(method, path, request)
    33  	if err != nil {
    34  		return fmt.Errorf("failed during hnsCallRawResponse: %v", err)
    35  	}
    36  	if !hnsresponse.Success {
    37  		return fmt.Errorf("hns failed with error : %s", hnsresponse.Error)
    38  	}
    39  
    40  	if len(hnsresponse.Output) == 0 {
    41  		return nil
    42  	}
    43  
    44  	logrus.Debugf("Network Response : %s", hnsresponse.Output)
    45  	err = json.Unmarshal(hnsresponse.Output, returnResponse)
    46  	if err != nil {
    47  		return err
    48  	}
    49  
    50  	return nil
    51  }
    52  

View as plain text