<commit_before>package main

import (
	"encoding/json"
	"net/http"


	"github.com/julienschmidt/httprouter"
)

/* Read functions
 */
func ListCheckConfiguration(w http.ResponseWriter, r *http.Request,
	params httprouter.Params) {
	defer PanicCatcher(w)

	returnChannel := make(chan somaResult)
	handler := handlerMap["checkConfigurationReadHandler"].(somaCheckConfigurationReadHandler)
	handler.input <- somaCheckConfigRequest{
		action: "list",
		reply:  returnChannel,
		CheckConfig: somaproto.CheckConfiguration{
			RepositoryId: params.ByName("repository"),
		},
	}
	result := <-returnChannel

	// declare here since goto does not jump over declarations
	cReq := somaproto.CheckConfigurationRequest{}
	cReq.Filter = &somaproto.CheckConfigurationFilter{}
	if result.Failure() {
		goto skip
	}

	_ = DecodeJsonBody(r, &cReq)
	if cReq.Filter.Name != "" {
		filtered := make([]somaCheckConfigResult, 0)
		for _, i := range result.CheckConfigs {
			if i.CheckConfig.Name == cReq.Filter.Name {
				filtered = append(filtered, i)
			}
		}
		result.CheckConfigs = filtered
	}

skip:
	SendCheckConfigurationReply(&w, &result)
}

func ShowCheckConfiguration(w http.ResponseWriter, r *http.Request,
	params httprouter.Params) {
	defer PanicCatcher(w)

	returnChannel := make(chan somaResult)
	handler := handlerMap["checkConfigurationReadHandler"].(somaCheckConfigurationReadHandler)
	handler.input <- somaCheckConfigRequest{
		action: "show",
		reply:  returnChannel,
		CheckConfig: somaproto.CheckConfiguration{
			Id:           params.ByName("check"),
			RepositoryId: params.ByName("repository"),
		},
	}
	result := <-returnChannel

	SendCheckConfigurationReply(&w, &result)
}

/* Write functions
 */
func AddCheckConfiguration(w http.ResponseWriter, r *http.Request,
	params httprouter.Params) {
	defer PanicCatcher(w)

	returnChannel := make(chan somaResult)
	result := <-returnChannel

	SendCheckConfigurationReply(&w, &result)
}<commit_msg>Implement AddCheckConfiguration forwarding to GuidePost<commit_after>package main

import (
	"encoding/json"
	"fmt"
	"net/http"


	"github.com/julienschmidt/httprouter"
)

/* Read functions
 */
func ListCheckConfiguration(w http.ResponseWriter, r *http.Request,
	params httprouter.Params) {
	defer PanicCatcher(w)

	returnChannel := make(chan somaResult)
	handler := handlerMap["checkConfigurationReadHandler"].(somaCheckConfigurationReadHandler)
	handler.input <- somaCheckConfigRequest{
		action: "list",
		reply:  returnChannel,
		CheckConfig: somaproto.CheckConfiguration{
			RepositoryId: params.ByName("repository"),
		},
	}
	result := <-returnChannel

	// declare here since goto does not jump over declarations
	cReq := somaproto.CheckConfigurationRequest{}
	cReq.Filter = &somaproto.CheckConfigurationFilter{}
	if result.Failure() {
		goto skip
	}

	_ = DecodeJsonBody(r, &cReq)
	if cReq.Filter.Name != "" {
		filtered := make([]somaCheckConfigResult, 0)
		for _, i := range result.CheckConfigs {
			if i.CheckConfig.Name == cReq.Filter.Name {
				filtered = append(filtered, i)
			}
		}
		result.CheckConfigs = filtered
	}

skip:
	SendCheckConfigurationReply(&w, &result)
}

func ShowCheckConfiguration(w http.ResponseWriter, r *http.Request,
	params httprouter.Params) {
	defer PanicCatcher(w)

	returnChannel := make(chan somaResult)
	handler := handlerMap["checkConfigurationReadHandler"].(somaCheckConfigurationReadHandler)
	handler.input <- somaCheckConfigRequest{
		action: "show",
		reply:  returnChannel,
		CheckConfig: somaproto.CheckConfiguration{
			Id:           params.ByName("check"),
			RepositoryId: params.ByName("repository"),
		},
	}
	result := <-returnChannel

	SendCheckConfigurationReply(&w, &result)
}

/* Write functions
 */
func AddCheckConfiguration(w http.ResponseWriter, r *http.Request,
	params httprouter.Params) {
	defer PanicCatcher(w)

	cReq := somaproto.CheckConfigurationRequest{}
	if err := DecodeJsonBody(r, &cReq); err != nil {
		DispatchBadRequest(&w, err)
		return
	}

	returnChannel := make(chan somaResult)
	handler := handlerMap["guidePost"].(guidePost)
	handler.input <- treeRequest{
		RequestType: "check",
		Action:      fmt.Sprintf("add_check_to_%s", cReq.CheckConfiguration.ObjectType),
		reply:       returnChannel,
		CheckConfig: somaCheckConfigRequest{
			action:      "check_configuration_new",
			CheckConfig: *cReq.CheckConfiguration,
		},
	}
	result := <-returnChannel
	SendCheckConfigurationReply(&w, &result)
}
{'fraction_non_alphanumeric': 0.11837935717519239, 'fraction_numerical': 0.0004526935264825713, 'mean_word_length': 5.053424657534246, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 3, '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': '4189569', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1375, 'n_words': 275}