<commit_before>package params

import (
	"io/ioutil"
	"net/http"
	"net/url"
	"regexp"
)

// Type for http post body
type PostBody []byte // Byte array with request body

// Get params stands for "query params"
type GetParams map[string]string

type Params struct {
	Query      GetParams
	Body       PostBody
	PathParams PathParams
}

func NewParams(request *http.Request, pattern *regexp.Regexp, path string) (*Params, error) {
	body, err := ioutil.ReadAll(request.Body)
	if err != nil {
		return nil, err
	}

	return &Params{
		Query:      ValuesToGetParams(request.URL.Query()),
		Body:       body,
		PathParams: ExtractPathParams(pattern, path),
	}, nil
}

func ExtractParams(req *http.Request) *Params {
	return req.Context().Value("params").(*Params)
}

// Converts url.Url.Query() from "Values" (map[string][]string)
// to "getParams" (map[string]string)
func ValuesToGetParams(values url.Values) GetParams {
	var params map[string]string
	for key := range values {
		params[key] = values.Get(key)
	}
	return params
}

// Example: url "/api/v1/users/599a49bacdf43b817eeea57b" and pattern `/api/v1/users/:id`
// path params = {"id": "599a49bacdf43b817eeea57b"}
type PathParams map[string]string

// Extract path params from path
func ExtractPathParams(pattern *regexp.Regexp, path string) PathParams {
	match := pattern.FindStringSubmatch(path)
	result := make(PathParams)<commit_msg>fix get params from get query<commit_after>package params

import (
	"io/ioutil"
	"net/http"
	"net/url"
	"regexp"
)

// Type for http post body
type PostBody []byte // Byte array with request body

// Get params stands for "query params"
type GetParams map[string]string

type Params struct {
	Query      GetParams
	Body       PostBody
	PathParams PathParams
}

func NewParams(request *http.Request, pattern *regexp.Regexp, path string) (*Params, error) {
	body, err := ioutil.ReadAll(request.Body)
	if err != nil {
		return nil, err
	}

	return &Params{
		Query:      ValuesToGetParams(request.URL.Query()),
		Body:       body,
		PathParams: ExtractPathParams(pattern, path),
	}, nil
}

func ExtractParams(req *http.Request) *Params {
	return req.Context().Value("params").(*Params)
}

// Converts url.Url.Query() from "Values" (map[string][]string)
// to "getParams" (map[string]string)
func ValuesToGetParams(values url.Values) GetParams {
	params := make(map[string]string)
	for key := range values {
		params[key] = values.Get(key)
	}
	return params
}

// Example: url "/api/v1/users/599a49bacdf43b817eeea57b" and pattern `/api/v1/users/:id`
// path params = {"id": "599a49bacdf43b817eeea57b"}
type PathParams map[string]string

// Extract path params from path
func ExtractPathParams(pattern *regexp.Regexp, path string) PathParams {
	match := pattern.FindStringSubmatch(path)
	result := make(PathParams)
{'fraction_non_alphanumeric': 0.12861736334405144, 'fraction_numerical': 0.018578063594140763, 'mean_word_length': 4.384615384615385, 'pattern_counts': {'":': 2, '<': 3, '<?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': '5239355', 'n_tokens_mistral': 995, 'n_tokens_neox': 943, 'n_words': 249}