<commit_before>package media

import (
	"net/http"
	"github.com/gorilla/mux"
	"strconv"
	"io/ioutil"
)

func GetMedia(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	f := vars["idMedia"]
	idMedia, _ := strconv.Atoi(f)

	if idMedia > 0 {

		config, err := ioutil.ReadFile("data/media.config.json")
		check(err)

		if err == nil {
			w.Write([]byte(config))
		}
	}
}

func check(e error) {
	if e != nil {
		panic(e)
	}
}<commit_msg>[Improve] Load medias configuration from memory<commit_after>package media

import (
	"net/http"
	"github.com/gorilla/mux"
	"strconv"
	"io/ioutil"
	"encoding/json"
	"errors"
)

var Medias []Media

func LoadMedias() {
	content, err := ioutil.ReadFile("data/media.config.json")
	check(err)

	err = json.Unmarshal(content, &Medias)
	check(err)
}

func GetMedia(idMedia int) (*Media, error) {
	for _, m := range Medias {
		if idMedia == m.ID {
			return &m, nil
		}
	}

	return nil, errors.New("NO_MEDIA_FOUND")
}

func HandleGetMedia(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	f := vars["idMedia"]
	idMedia, _ := strconv.Atoi(f)

	m, err := GetMedia(idMedia)
	if err != nil {
		writeResponseWithError(w, http.StatusNotFound)
		return
	}

	b, err := json.Marshal(*m)
	if err != nil {
		writeResponseWithError(w, http.StatusNotFound)
		return
	}

	w.Write([]byte(b))

}

func writeResponseWithError(w http.ResponseWriter, errorCode int) {
	w.WriteHeader(errorCode)
}

func check(e error) {
	if e != nil {
		panic(e)
	}
}
{'fraction_non_alphanumeric': 0.15991902834008098, 'fraction_numerical': 0.0006747638326585695, 'mean_word_length': 3.910596026490066, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '1050970', 'n_tokens_mistral': 628, 'n_tokens_neox': 600, 'n_words': 124}