<commit_before>// +build lambdabinary,!noop

package cgo

// #include <stdlib.h>
// #include <string.h>
import "C"

import (
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
	"net/http/httptest"
	"net/url"
	"os"
	"strconv"
	"strings"
	"sync"
	"syscall"
	"time"

	"github.com/Sirupsen/logrus"
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/credentials"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/cloudwatch"
	"github.com/mweagle/Sparta"
	spartaAWS "github.com/mweagle/Sparta/aws"
)

// Lock to update CGO related config
var muCredentials sync.Mutex
var pythonCredentialsValue credentials.Value

////////////////////////////////////////////////////////////////////////////////
// lambdaFunctionErrResponse is the struct used to return a CGO error response
type lambdaFunctionErrResponse struct {
	Code    int         `json:"code"`
	Status  string      `json:"status"`
	Headers http.Header `json:"headers"`
	Error   string      `json:"error"`
}

////////////////////////////////////////////////////////////////////////////////
// cgoLambdaHTTPAdapterStruct is the binding between the various params
// supplied to the LambdaHandler
type cgoLambdaHTTPAdapterStruct struct {
	serviceName               string
	lambdaHTTPHandlerInstance *sparta.LambdaHTTPHandler
	logger                    *logrus.Logger
}

var cgoLambdaHTTPAdapter cgoLambdaHTTPAdapterStruct

////////////////////////////////////////////////////////////////////////////////
// cgoMain is the primary entrypoint for the library version
func cgoMain(callerFile string,
	serviceName string,
	serviceDescription string,
	lambdaAWSInfos []*sparta.LambdaAWSInfo,
	api *sparta.API,
	site *sparta.S3Site,
	workflowHooks *sparta.WorkflowHooks) error {
	logger, loggerErr := sparta.NewLogger("info")
	if nil != loggerErr {
		panic("Failed to initialize logger")
	}
	cgoLambdaHTTPAdapter = cgoLambdaHTTPAdapterStruct{
		serviceName:               serviceName,
		lambdaHTTPHandlerInstance: sparta.NewLambdaHTTPHandler(lambdaAWSInfos, logger),
		logger: logger,
	}
	return nil
}

func makeRequest(functionName string,
	eventBody io.ReadCloser,
	eventBodySize int64) ([]byte, http.Header, error) {

	// Create an http.Request object with this data...
	spartaResp := httptest.NewRecorder()
	spartaReq := &http.Request{
		Method: "POST",
		URL: &url.URL{
			Scheme: "http",
			Path:   fmt.Sprintf("/%s", functionName),
		},
		Proto:            "HTTP/1.1",
		ProtoMajor:       1,
		ProtoMinor:       1,<commit_msg>Formatting only, no functional change<commit_after>// +build lambdabinary,!noop

package cgo

// #include <stdlib.h>
// #include <string.h>
import "C"

import (
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
	"net/http/httptest"
	"net/url"
	"os"
	"strconv"
	"strings"
	"sync"
	"syscall"
	"time"

	"github.com/Sirupsen/logrus"
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/credentials"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/cloudwatch"
	"github.com/mweagle/Sparta"
	spartaAWS "github.com/mweagle/Sparta/aws"
)

// Lock to update CGO related config
var muCredentials sync.Mutex
var pythonCredentialsValue credentials.Value

////////////////////////////////////////////////////////////////////////////////
// lambdaFunctionErrResponse is the struct used to return a CGO error response
type lambdaFunctionErrResponse struct {
	Code    int         `json:"code"`
	Status  string      `json:"status"`
	Headers http.Header `json:"headers"`
	Error   string      `json:"error"`
}

////////////////////////////////////////////////////////////////////////////////
// cgoLambdaHTTPAdapterStruct is the binding between the various params
// supplied to the LambdaHandler
type cgoLambdaHTTPAdapterStruct struct {
	serviceName               string
	lambdaHTTPHandlerInstance *sparta.LambdaHTTPHandler
	logger                    *logrus.Logger
}

var cgoLambdaHTTPAdapter cgoLambdaHTTPAdapterStruct

////////////////////////////////////////////////////////////////////////////////
// cgoMain is the primary entrypoint for the library version
func cgoMain(callerFile string,
	serviceName string,
	serviceDescription string,
	lambdaAWSInfos []*sparta.LambdaAWSInfo,
	api *sparta.API,
	site *sparta.S3Site,
	workflowHooks *sparta.WorkflowHooks) error {

	logger, loggerErr := sparta.NewLogger("info")
	if nil != loggerErr {
		panic("Failed to initialize logger")
	}
	cgoLambdaHTTPAdapter = cgoLambdaHTTPAdapterStruct{
		serviceName:               serviceName,
		lambdaHTTPHandlerInstance: sparta.NewLambdaHTTPHandler(lambdaAWSInfos, logger),
		logger: logger,
	}
	return nil
}

func makeRequest(functionName string,
	eventBody io.ReadCloser,
	eventBodySize int64) ([]byte, http.Header, error) {

	// Create an http.Request object with this data...
	spartaResp := httptest.NewRecorder()
	spartaReq := &http.Request{
		Method: "POST",
		URL: &url.URL{
			Scheme: "http",
			Path:   fmt.Sprintf("/%s", functionName),
		},
		Proto:            "HTTP/1.1",
		ProtoMajor:       1,
		ProtoMinor:       1,
{'fraction_non_alphanumeric': 0.19786519074915992, 'fraction_numerical': 0.0027673453251630758, 'mean_word_length': 2.553370786516854, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5793792', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1568, 'n_words': 357}