<commit_before>package main

import (
	"fmt"
	"net/http"
	"os"
	"strings"

	"github.com/dghubble/sling"
)

const baseURL = "https://openwhisk.ng.bluemix.net/api/v1/web/estesp%40us.ibm.com_dev/default/archList.json"

// QueryParams defines the parameters sent; in our case only "image" is needed
type QueryParams struct {
	Image string `url:"image"`
}

// ImageDataResponse holds the payload response on success
type ImageDataResponse struct {
	ImageData Payload `json:"payload,omitempty"`
	Error     string  `json:"error,omitempty"`
}

// Payload contains the JSON struct we get from the web action
type Payload struct {
	ManifestList string   `json:"manifestList,omitempty"`
	Tag          string   `json:"tag,omitempty"`
	ID           string   `json:"_id,omitempty"`
	RepoTags     []string `json:"repoTags,omitempty"`
	ArchList     []string `json:"archList,omitempty"`
	Platform     string   `json:"platform,omitempty"`
}

func main() {
	if len(os.Args) < 2 {
		fmt.Printf("ERROR: Must provide an image name as a command line parameter.\n")
		os.Exit(1)
	}
	qparam := &QueryParams{
		Image: os.Args[1],
	}
	response := new(ImageDataResponse)
	resp, err := sling.New().Base(baseURL).QueryStruct(qparam).ReceiveSuccess(response)
	if err != nil {
		fmt.Printf("ERROR: failed to query backend: %v\n", err)
		os.Exit(1)
	}
	os.Exit(processResponse(resp, os.Args[1], response))
}

func processResponse(resp *http.Response, imageName string, response *ImageDataResponse) int {
	if resp.StatusCode != 200 {
		// non-success RC from our http request
		fmt.Printf("ERROR: Failure code from our HTTP request: %d\n", resp.StatusCode)
		return 1
	}
	if response.Error != "" {
		// print out error
		fmt.Printf("ERROR: %s\n", response.Error)
		return 1
	}
	printManifestInfo(imageName, response)
	return 0
}

func printManifestInfo(imageName string, response *ImageDataResponse) {
	fmt.Printf("Image: %s\n", imageName)
	fmt.Printf(" * Manifest List: %s\n", response.ImageData.ManifestList)
	if strings.Compare(response.ImageData.ManifestList, "Yes") == 0 {
		fmt.Println(" * Supported platforms:")
		for _, archosPair := range response.ImageData.ArchList {
			fmt.Printf("   - %s\n", archosPair)
		}
	} else {
		fmt.Printf(" * Supports: %s\n", response.ImageData.Platform)
	}
	fmt.Println("")
}<commit_msg>Update mquery to use Lambda function<commit_after>package main

import (
	"fmt"
	"net/http"
	"os"

	"github.com/dghubble/sling"
	ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)

const baseURL = "https://2xopp470jc.execute-api.us-east-2.amazonaws.com/mquery"

// QueryParams defines the parameters sent; in our case only "image" is needed
type QueryParams struct {
	Image string `url:"image"`
}

// ErrorResponse holds the payload response on failure HTTP codes
type ErrorResponse struct {
	Error string `json:"error,omitempty"`
}

// Image contains the JSON struct we get from success
type Image struct {
	CacheTS   int64              `json:"cachets"`
	IsList    bool               `json:"islist"`
	ImageName string             `json:"imagename"`
	Digest    string             `json:"digest"`
	ArchList  []ocispec.Platform `json:"archlist"`
}

func main() {
	if len(os.Args) < 2 {
		fmt.Printf("ERROR: Must provide an image name as a command line parameter.\n")
		os.Exit(1)
	}
	qparam := &QueryParams{
		Image: os.Args[1],
	}
	image := new(Image)
	errResp := new(ErrorResponse)
	resp, err := sling.New().Base(baseURL).QueryStruct(qparam).Receive(image, errResp)
	if err != nil {
		fmt.Printf("ERROR: failed to query backend: %v\n", err)
		os.Exit(1)
	}
	os.Exit(processResponse(resp, os.Args[1], errResp, image))
}

func processResponse(resp *http.Response, imageName string, errResp *ErrorResponse, image *Image) int {
	if resp.StatusCode != 200 {
		// non-success RC from our http request
		fmt.Printf("ERROR: %s\n", errResp.Error)
		return 1
	}
	printManifestInfo(imageName, image)
	return 0
}

func printManifestInfo(imageName string, image *Image) {
	fmt.Printf("Image: %s\n", imageName)
	list := "Yes"
	if !image.IsList {
		list = "No"
	}
	fmt.Printf(" * Manifest List: %s\n", list)
	if image.IsList {
		fmt.Println(" * Supported platforms:")
		for _, platform := range image.ArchList {
			platformOutput := parsePlatform(platform)
			fmt.Printf("   - %s\n", platformOutput)
		}
	} else {
		fmt.Printf(" * Supports: %s\n", parsePlatform(image.ArchList[0]))
	}
	fmt.Println("")
}

func parsePlatform(platform ocispec.Platform) string {
	platformStr := fmt.Sprintf("%s/%s", platform.OS, platform.Architecture)
	if len(platform.Variant) > 0 {
		platformStr = platformStr + "/" + platform.Variant
	}
	if platform.OS == "windows" {
		if len(platform.OSVersion) > 0 {
			platformStr = platformStr + ":" + platform.OSVersion
		}
	}
	return platformStr
}
{'fraction_non_alphanumeric': 0.13994536667367094, 'fraction_numerical': 0.007564614414793024, 'mean_word_length': 4.0052576235541535, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '7403586', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1620, 'n_words': 405}