Esempio n. 1
0
func Evaluate(server string, e Evaluation) (EvaluationResult, int) {
	jsonQuery, err := json.Marshal(e)
	if err != nil {
		util.PrintFatal("Error converting request into valid JSON.")
	}
	//PrintDebug(fmt.Sprintf("JSON Query: %s", jsonQuery))

	query := bytes.NewBuffer(jsonQuery)

	parsedServer, err := url.Parse(server)
	if err != nil {
		util.PrintFatal("Could not parse given server URL.")
	}

	resp, err := http.Post(parsedServer.String(), "application/json", query)
	if err != nil {
		util.PrintFatal("Could not successfully POST the query to the server.")
	}

	defer resp.Body.Close()
	body, _ := ioutil.ReadAll(resp.Body)
	if err != nil {
		util.PrintFatal("Could not read the response from the server.")
	}

	util.PrintDebug(fmt.Sprintf("JSON Response: %s", string(body)))

	var result EvaluationResult
	err = json.Unmarshal(body, &result)
	if err != nil {
		util.PrintFatal("Error decoding JSON response from the server.")
	}

	return result, resp.StatusCode
}
Esempio n. 2
0
func main() {
	flag.Usage = usage
	flag.Parse()

	if flag.NFlag() == 0 {
		flag.Usage()
	}

	util.PrintDebug("Requesting evaluation...")
	code, _ := ioutil.ReadAll(os.Stdin)
	e := evaluate.Evaluation{
		Language: *language,
		Code:     string(code),
	}

	result, statusCode := evaluate.Evaluate(*server, e)

	if statusCode != 200 {
		util.PrintFatal(fmt.Sprintf("HTTP Code %d", statusCode))
	} else {
		if result.CompilationResult != nil {
			fmt.Println("---------- Compilation ----------")
			printResult(*result.CompilationResult)
			fmt.Println("----------  Execution  ----------")
		}
		printResult(result)
		os.Exit(result.Exitcode)
	}
}