<commit_before>package main

import (
	"encoding/json"
	"fmt"
	"github.com/gorilla/handlers"
	"github.com/gorilla/mux"
	"github.com/jawher/mow.cli"
	"io"
	"log"
	"net/http"
	"os"
	"os/signal"
	"runtime/pprof"
	"sync"
)

func main() {

	f, err := os.Create("/tmp/cpuprof")
	if err != nil {
		panic(err)
	}
	pprof.StartCPUProfile(f)
	defer pprof.StopCPUProfile()

	app := cli.App("restorage", "A RESTful storage API with pluggable backends")
	port := app.IntOpt("port", 8080, "Port to listen on")

	app.Command("elastic", "use the elastic search backend", func(cmd *cli.Cmd) {
		url := cmd.StringArg("URL", "", "elastic search endpoint url")
		indexName := cmd.StringOpt("index-name", "store", "elastic search index name")
		cmd.Action = func() {
			println(*url)
			serve(NewElasticEngine(*url, *indexName), *port)
		}

	})

	app.Command("mongo", "use the mongodb backend", func(cmd *cli.Cmd) {
		hostports := cmd.StringArg("HOSTS", "", "hostname1:port1,hostname2:port2...")
		dbname := cmd.StringOpt("dbname", "store", "database name")
		cmd.Action = func() {
			serve(NewMongoEngine(*dbname, *hostports), *port)
		}

	})

	app.Run(os.Args)

}

func serve(engine Engine, port int) {
	ah := apiHandlers{engine}

	m := mux.NewRouter()
	http.Handle("/", handlers.CombinedLoggingHandler(os.Stdout, m))

	m.HandleFunc("/{collection}/_count", ah.countHandler).Methods("GET")
	m.HandleFunc("/{collection}/{id}", ah.idReadHandler).Methods("GET")
	m.HandleFunc("/{collection}/{id}", ah.idWriteHandler).Methods("PUT")
	m.HandleFunc("/{collection}/", ah.dropHandler).Methods("DELETE")
	m.HandleFunc("/{collection}/", ah.putAllHandler).Methods("PUT")
	m.HandleFunc("/{collection}/", ah.dumpAll).Methods("GET")<commit_msg>remove noise<commit_after>package main

import (
	"encoding/json"
	"fmt"
	"github.com/gorilla/handlers"
	"github.com/gorilla/mux"
	"github.com/jawher/mow.cli"
	"io"
	"log"
	"net/http"
	"os"
	"os/signal"
	"runtime/pprof"
	"sync"
)

func main() {

	f, err := os.Create("/tmp/cpuprof")
	if err != nil {
		panic(err)
	}
	pprof.StartCPUProfile(f)
	defer pprof.StopCPUProfile()

	app := cli.App("restorage", "A RESTful storage API with pluggable backends")
	port := app.IntOpt("port", 8080, "Port to listen on")

	app.Command("elastic", "use the elastic search backend", func(cmd *cli.Cmd) {
		url := cmd.StringArg("URL", "", "elastic search endpoint url")
		indexName := cmd.StringOpt("index-name", "store", "elastic search index name")
		cmd.Action = func() {
			serve(NewElasticEngine(*url, *indexName), *port)
		}

	})

	app.Command("mongo", "use the mongodb backend", func(cmd *cli.Cmd) {
		hostports := cmd.StringArg("HOSTS", "", "hostname1:port1,hostname2:port2...")
		dbname := cmd.StringOpt("dbname", "store", "database name")
		cmd.Action = func() {
			serve(NewMongoEngine(*dbname, *hostports), *port)
		}

	})

	app.Run(os.Args)

}

func serve(engine Engine, port int) {
	ah := apiHandlers{engine}

	m := mux.NewRouter()
	http.Handle("/", handlers.CombinedLoggingHandler(os.Stdout, m))

	m.HandleFunc("/{collection}/_count", ah.countHandler).Methods("GET")
	m.HandleFunc("/{collection}/{id}", ah.idReadHandler).Methods("GET")
	m.HandleFunc("/{collection}/{id}", ah.idWriteHandler).Methods("PUT")
	m.HandleFunc("/{collection}/", ah.dropHandler).Methods("DELETE")
	m.HandleFunc("/{collection}/", ah.putAllHandler).Methods("PUT")
	m.HandleFunc("/{collection}/", ah.dumpAll).Methods("GET")
{'fraction_non_alphanumeric': 0.19970588235294118, 'fraction_numerical': 0.004705882352941176, 'mean_word_length': 4.925087108013937, 'pattern_counts': {'":': 0, '<': 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': '2150894', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1249, 'n_words': 229}