func (ic *InvocationClient) getInitErrorURL() string {
	return fmt.Sprintf("http://%s/%s/extension/init/error", ic.baseUrl, ic.version)
}
getInitErrorURL returns the Lambda Extension initialization error URL
package client
import (
	"bytes"
	"context"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"os"
	"path/filepath"
	"github.com/newrelic/newrelic-lambda-extension/lambda/extension/api"
	"github.com/newrelic/newrelic-lambda-extension/util"
)
type InvocationClient struct {
	version     string
	baseUrl     string
	httpClient  http.Client
	extensionId string
}
type RegistrationClient struct {
	extensionName string
	version       string
	baseUrl       string
	httpClient    http.Client
}
func New(httpClient http.Client) *RegistrationClient {
	exePath, err := os.Executable()
	if err != nil {
		util.Fatal(err)
	}
	exeName := filepath.Base(exePath)
	return &RegistrationClient{
		extensionName: exeName,
		version:       api.Version,
		baseUrl:       os.Getenv(api.LambdaHostPortEnvVar),
		httpClient:    httpClient,
	}
}
func (rc *RegistrationClient) getRegisterURL() string {
	return fmt.Sprintf("http://%s/%s/extension/register", rc.baseUrl, rc.version)
}
func (rc *RegistrationClient) RegisterDefault(ctx context.Context) (*InvocationClient, *api.RegistrationResponse, error) {
	defaultEvents := []api.LifecycleEvent{api.Invoke, api.Shutdown}
	defaultRequest := api.RegistrationRequest{Events: defaultEvents}
	return rc.Register(ctx, defaultRequest)
}
func (rc *RegistrationClient) Register(ctx context.Context, registrationRequest api.RegistrationRequest) (*InvocationClient, *api.RegistrationResponse, error) {
	registrationRequestJson, err := json.Marshal(registrationRequest)
	if err != nil {
		return nil, nil, fmt.Errorf("error occurred while marshaling registration request %s", err)
	}
	req, err := http.NewRequestWithContext(ctx, "POST", rc.getRegisterURL(), bytes.NewBuffer(registrationRequestJson))
	if err != nil {
		return nil, nil, fmt.Errorf("error occurred while creating registration request %s", err)
	}
	req.Header.Set(api.ExtensionNameHeader, rc.extensionName)
	res, err := rc.httpClient.Do(req)
	if err != nil {
		return nil, nil, fmt.Errorf("error occurred while making registration request %s", err)
	}
	defer util.Close(res.Body)
	if res.StatusCode == http.StatusInternalServerError {
		util.Panic("error occurred while making registration request: ", res.Status)
	}
	if res.StatusCode != http.StatusOK {
		return nil, nil, fmt.Errorf("error occurred while making registration request: %s", res.Status)
	}
	bodyBytes, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return nil, nil, err
	}
	util.Debugf("Registration response: %s", bodyBytes)
	var registrationResponse api.RegistrationResponse
	err = json.Unmarshal(bodyBytes, &registrationResponse)
	if err != nil {
		return nil, nil, err
	}
	id, exists := res.Header[api.ExtensionIdHeader]
	if !exists {
		return nil, nil, fmt.Errorf("missing extension identifier. Response body %s", bodyBytes)
	}
	invocationClient := InvocationClient{rc.version, rc.baseUrl, rc.httpClient, id[0]}
	return &invocationClient, &registrationResponse, nil
}
func (ic *InvocationClient) getNextEventURL() string {
	return fmt.Sprintf("http://%s/%s/extension/event/next", ic.baseUrl, ic.version)
}