<commit_before>package application

import (
	"encoding/json"
	"fmt"
	"github.com/codegangsta/negroni"
	"github.com/facebookgo/grace/gracehttp"
	"github.com/gorilla/mux"
	"github.com/jmoiron/jsonq"
	"github.com/meatballhat/negroni-logrus"
	"github.com/rs/cors"
	"github.com/thoas/picfit/middleware"
	"io/ioutil"
	"net/http"
	"runtime"
	"strconv"
	"strings"
)

var App = NewApplication()

var KVStores = map[string]KVStoreParameter{
	"redis": RedisKVStoreParameter,
	"cache": CacheKVStoreParameter,
}

var Storages = map[string]StorageParameter{
	"s3": S3StorageParameter,
	"fs": FileSystemStorageParameter,
}

func Run(path string) error {
	runtime.GOMAXPROCS(runtime.NumCPU())

	content, err := ioutil.ReadFile(path)

	if err != nil {
		return err
	}

	data := map[string]interface{}{}
	dec := json.NewDecoder(strings.NewReader(string(content)))
	dec.Decode(&data)
	jq := jsonq.NewQuery(data)

	for _, initializer := range Initializers {
		err = initializer(jq)

		panicIf(err)
	}

	App.Router = mux.NewRouter()
	App.Router.NotFoundHandler = NotFoundHandler()

	App.Router.Handle("/redirect", RedirectHandler)
	App.Router.Handle("/redirect/{sig}/{op}/x{h:[\\d]+}/{path:[\\w\\-/.]+}", RedirectHandler)
	App.Router.Handle("/redirect/{sig}/{op}/{w:[\\d]+}x/{path:[\\w\\-/.]+}", RedirectHandler)
	App.Router.Handle("/redirect/{sig}/{op}/{w:[\\d]+}x{h:[\\d]+}/{path:[\\w\\-/.]+}", RedirectHandler)
	App.Router.Handle("/redirect/{op}/x{h:[\\d]+}/{path:[\\w\\-/.]+}", RedirectHandler)
	App.Router.Handle("/redirect/{op}/{w:[\\d]+}x/{path:[\\w\\-/.]+}", RedirectHandler)
	App.Router.Handle("/redirect/{op}/{w:[\\d]+}x{h:[\\d]+}/{path:[\\w\\-/.]+}", RedirectHandler)

	App.Router.Handle("/display", ImageHandler)
	App.Router.Handle("/display/{sig}/{op}/x{h:[\\d]+}/{path:[\\w\\-/.]+}", ImageHandler)
	App.Router.Handle("/display/{sig}/{op}/{w:[\\d]+}x/{path:[\\w\\-/.]+}", ImageHandler)
	App.Router.Handle("/display/{sig}/{op}/{w:[\\d]+}x{h:[\\d]+}/{path:[\\w\\-/.]+}", ImageHandler)
	App.Router.Handle("/display/{op}/x{h:[\\d]+}/{path:[\\w\\-/.]+}", ImageHandler)
	App.Router.Handle("/display/{op}/{w:[\\d]+}x/{path:[\\w\\-/.]+}", ImageHandler)
	App.Router.Handle("/display/{op}/{w:[\\d]+}x{h:[\\d]+}/{path:[\\w\\-/.]+}", ImageHandler)

	App.Router.Handle("/get", GetHandler)
	App.Router.Handle("/get/{sig}/op}/x{h:[\\d]+}/{path:[\\w\\-/.]+}", GetHandler)
	App.Router.Handle("/get/{sig}/op}/{w:[\\d]+}x/{path:[\\w\\-/.]+}", GetHandler)
	App.Router.Handle("/get/{sig}/op}/{w:[\\d]+}x{h:[\\d]+}/{path:[\\w\\-/.]+}", GetHandler)
	App.Router.Handle("/get/{op}/x{h:[\\d]+}/{path:[\\w\\-/.]+}", GetHandler)
	App.Router.Handle("/get/{op}/{w:[\\d]+}x/{path:[\\w\\-/.]+}", GetHandler)
	App.Router.Handle("/get/{op}/{w:[\\d]+}x{h:[\\d]+}/{path:[\\w\\-/.]+}", GetHandler)

	allowedOrigins, err := jq.ArrayOfStrings("allowed_origins")
	allowedMethods, err := jq.ArrayOfStrings("allowed_methods")

	n := negroni.New(&middleware.Recovery{
		Raven:      App.Raven,
		Logger:     App.Logger.Error,
		PrintStack: true,
		StackAll:   false,
		StackSize:  1024 * 8,
	}, &middleware.Logger{App.Logger.Info})
	n.Use(cors.New(cors.Options{
		AllowedOrigins: allowedOrigins,
		AllowedMethods: allowedMethods,<commit_msg>Add debug option in config<commit_after>package application

import (
	"encoding/json"
	"fmt"
	"github.com/codegangsta/negroni"
	"github.com/facebookgo/grace/gracehttp"
	"github.com/gorilla/mux"
	"github.com/jmoiron/jsonq"
	"github.com/meatballhat/negroni-logrus"
	"github.com/rs/cors"
	"github.com/thoas/picfit/middleware"
	"io/ioutil"
	"net/http"
	"runtime"
	"strconv"
	"strings"
)

var App = NewApplication()

var KVStores = map[string]KVStoreParameter{
	"redis": RedisKVStoreParameter,
	"cache": CacheKVStoreParameter,
}

var Storages = map[string]StorageParameter{
	"s3": S3StorageParameter,
	"fs": FileSystemStorageParameter,
}

func Run(path string) error {
	runtime.GOMAXPROCS(runtime.NumCPU())

	content, err := ioutil.ReadFile(path)

	if err != nil {
		return err
	}

	data := map[string]interface{}{}
	dec := json.NewDecoder(strings.NewReader(string(content)))
	dec.Decode(&data)
	jq := jsonq.NewQuery(data)

	for _, initializer := range Initializers {
		err = initializer(jq)

		panicIf(err)
	}

	App.Router = mux.NewRouter()
	App.Router.NotFoundHandler = NotFoundHandler()

	App.Router.Handle("/redirect", RedirectHandler)
	App.Router.Handle("/redirect/{sig}/{op}/x{h:[\\d]+}/{path:[\\w\\-/.]+}", RedirectHandler)
	App.Router.Handle("/redirect/{sig}/{op}/{w:[\\d]+}x/{path:[\\w\\-/.]+}", RedirectHandler)
	App.Router.Handle("/redirect/{sig}/{op}/{w:[\\d]+}x{h:[\\d]+}/{path:[\\w\\-/.]+}", RedirectHandler)
	App.Router.Handle("/redirect/{op}/x{h:[\\d]+}/{path:[\\w\\-/.]+}", RedirectHandler)
	App.Router.Handle("/redirect/{op}/{w:[\\d]+}x/{path:[\\w\\-/.]+}", RedirectHandler)
	App.Router.Handle("/redirect/{op}/{w:[\\d]+}x{h:[\\d]+}/{path:[\\w\\-/.]+}", RedirectHandler)

	App.Router.Handle("/display", ImageHandler)
	App.Router.Handle("/display/{sig}/{op}/x{h:[\\d]+}/{path:[\\w\\-/.]+}", ImageHandler)
	App.Router.Handle("/display/{sig}/{op}/{w:[\\d]+}x/{path:[\\w\\-/.]+}", ImageHandler)
	App.Router.Handle("/display/{sig}/{op}/{w:[\\d]+}x{h:[\\d]+}/{path:[\\w\\-/.]+}", ImageHandler)
	App.Router.Handle("/display/{op}/x{h:[\\d]+}/{path:[\\w\\-/.]+}", ImageHandler)
	App.Router.Handle("/display/{op}/{w:[\\d]+}x/{path:[\\w\\-/.]+}", ImageHandler)
	App.Router.Handle("/display/{op}/{w:[\\d]+}x{h:[\\d]+}/{path:[\\w\\-/.]+}", ImageHandler)

	App.Router.Handle("/get", GetHandler)
	App.Router.Handle("/get/{sig}/op}/x{h:[\\d]+}/{path:[\\w\\-/.]+}", GetHandler)
	App.Router.Handle("/get/{sig}/op}/{w:[\\d]+}x/{path:[\\w\\-/.]+}", GetHandler)
	App.Router.Handle("/get/{sig}/op}/{w:[\\d]+}x{h:[\\d]+}/{path:[\\w\\-/.]+}", GetHandler)
	App.Router.Handle("/get/{op}/x{h:[\\d]+}/{path:[\\w\\-/.]+}", GetHandler)
	App.Router.Handle("/get/{op}/{w:[\\d]+}x/{path:[\\w\\-/.]+}", GetHandler)
	App.Router.Handle("/get/{op}/{w:[\\d]+}x{h:[\\d]+}/{path:[\\w\\-/.]+}", GetHandler)

	allowedOrigins, err := jq.ArrayOfStrings("allowed_origins")
	allowedMethods, err := jq.ArrayOfStrings("allowed_methods")

	debug, err := jq.Bool("debug")

	if err != nil {
		debug = true
	}

	n := negroni.New(&middleware.Recovery{
		Raven:      App.Raven,
		Logger:     App.Logger.Error,
		PrintStack: debug,
		StackAll:   false,
		StackSize:  1024 * 8,
	}, &middleware.Logger{App.Logger.Info})
	n.Use(cors.New(cors.Options{
		AllowedOrigins: allowedOrigins,
		AllowedMethods: allowedMethods,
{'fraction_non_alphanumeric': 0.2863995048738976, 'fraction_numerical': 0.0021661766981278044, 'mean_word_length': 4.1629392971246, 'pattern_counts': {'":': 8, '<': 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': '6234503', 'n_tokens_mistral': 2714, 'n_tokens_neox': 2614, 'n_words': 275}