<commit_before>package main

import (
	"fmt"
	"log"
	"net/http"
	"strings"

	"github.com/julienschmidt/httprouter"
)

func helloWorld(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	fmt.Fprintf(w, "Hello, World")
}

func catalog(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	catalog, err := Asset("config/settings.json")
	if err != nil {
		return
	}
	fmt.Fprintf(w, string(catalog))
}

func createInstance(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	dbname := fmt.Sprintf("d%s", ps.ByName("instance_id"))
	dashboard_url, err := createDatabase(strings.Replace(dbname, "-", "_", -1))

	if err == nil {
		fmt.Fprintf(w, dashboard_url)
	} else {
		w.WriteHeader(err.Code)
		fmt.Fprintf(w, err.Err.Error())
	}
}

func deleteInstance(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	dbname := fmt.Sprintf("d%s", ps.ByName("instance_id"))

	err := deleteDatabase(strings.Replace(dbname, "-", "_", -1))
	if err == nil {
		fmt.Fprintf(w, " ")
	} else {
		w.WriteHeader(err.Code)
		fmt.Fprintf(w, err.Err.Error())
	}
}

func Router() *httprouter.Router {
	router := httprouter.New()
	router.GET("/", helloWorld)
	router.GET("/v2/catalog", basicAuth(catalog))
	router.PUT("/v2/service_instances/:instance_id", basicAuth(createInstance))
	router.DELETE("/v2/service_instances/:instance_id", basicAuth(deleteInstance))
	return router
}

func main() {
	router := Router()
	log.Fatal(http.ListenAndServe(":8080", router))
}<commit_msg>Return json responses instead of strings.<commit_after>package main

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

	"github.com/julienschmidt/httprouter"
)

func helloWorld(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	fmt.Fprintf(w, "Hello, World")
}

func catalog(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	catalog, err := Asset("config/settings.json")
	if err != nil {
		return
	}
	fmt.Fprintf(w, string(catalog))
}

func createInstance(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	dbname := fmt.Sprintf("d%s", ps.ByName("instance_id"))
	dashboard_url, err := createDatabase(strings.Replace(dbname, "-", "_", -1))

	response := make(map[string]string)

	if err == nil {
		response["dashboard_url"] = dashboard_url
	} else {
		w.WriteHeader(err.Code)
		response["description"] = err.Err.Error()
	}
	w.Header().Set("Content-Type", "application/json")
	j, _ := json.Marshal(response)
	w.Write(j)
}

func deleteInstance(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	dbname := fmt.Sprintf("d%s", ps.ByName("instance_id"))

	response := make(map[string]string)
	err := deleteDatabase(strings.Replace(dbname, "-", "_", -1))
	if err != nil {
		w.WriteHeader(err.Code)
		response["description"] = err.Err.Error()
	}
	w.Header().Set("Content-Type", "application/json")
	j, _ := json.Marshal(response)
	w.Write(j)
}

func Router() *httprouter.Router {
	router := httprouter.New()
	router.GET("/", helloWorld)
	router.GET("/v2/catalog", basicAuth(catalog))
	router.PUT("/v2/service_instances/:instance_id", basicAuth(createInstance))
	router.DELETE("/v2/service_instances/:instance_id", basicAuth(deleteInstance))
	router.PUT("/v2/service_instances/:instance_id/service_bindings/:binding_id",
		basicAuth(createBinding))
	return router
}

func main() {
	router := Router()
	log.Fatal(http.ListenAndServe(":8080", router))
}
{'fraction_non_alphanumeric': 0.1746545133784181, 'fraction_numerical': 0.00558659217877095, 'mean_word_length': 5.1854545454545455, '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': '2378181', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1234, 'n_words': 214}