Exemplo n.º 1
0
// Handle handles http.Requests for the Compare.
func (resource Compare) Handle(request *trim.Request) trim.Response {
	query := request.QueryArguments()
	agent1, agent2, err := parseAgents(query)
	n, err := parseN(query)
	if err != nil {
		return NewGoogleJSONResponse(
			trim.Arguments{"message": err.Error()},
			http.StatusBadRequest,
		)
	}
	command := "mancalai_cli"
	args := []string{
		"-tool",
		"compare",
		"-agent1",
		agent1,
		"-agent2",
		agent2,
		"-n",
		n,
	}
	output, err := exec.Command(command, args...).Output()
	if err != nil {
		return NewGoogleJSONResponse(
			trim.Arguments{"message": fmt.Sprintf(
				"Couldn't complete command '%s'",
				command,
			)},
			http.StatusInternalServerError,
		)
	}
	var content map[string]interface{}
	if err := json.Unmarshal(output, &content); err != nil {
		return NewGoogleJSONResponse(
			trim.Arguments{
				"message": "Couldn't unmarshal content",
			},
			http.StatusInternalServerError,
		)
	}
	return NewGoogleJSONResponse(content, http.StatusOK)
}
Exemplo n.º 2
0
// Handle request by returning the file at the request's path.
func (f *FileController) Handle(request *trim.Request) trim.Response {
	return responses.NewStaticResponse(request.Path()[1:])
}