...
  
  
     1  
    18  
    19  package faas_openfaas
    20  
    21  import (
    22  	"encoding/json"
    23  	"io/ioutil"
    24  	"scheduler/log"
    25  	"scheduler/types"
    26  )
    27  
    28  func functionDeployApiCall(host string, function Function) (*types.FaasApiResponse, error) {
    29  	faas, err := json.Marshal(function)
    30  	if err != nil {
    31  		log.Log.Debugf("Passed function is not valid: %s", err.Error())
    32  		return nil, err
    33  	}
    34  	log.Log.Debugf("request json is %s", string(faas))
    35  
    36  	res, err := HttpPostJSON(GetApiSystemFunctionsUrl(host), string(faas))
    37  	if err != nil {
    38  		log.Log.Debugf("Could not contact OpenFaaS backend: %s", err.Error())
    39  		return nil, err
    40  	}
    41  
    42  	body, _ := ioutil.ReadAll(res.Body)
    43  	_ = res.Body.Close()
    44  
    45  	response := types.FaasApiResponse{
    46  		Headers:    res.Header,
    47  		Body:       body,
    48  		StatusCode: res.StatusCode,
    49  	}
    50  
    51  	return &response, err
    52  }
    53  
View as plain text