<commit_before>package main

import (
	"flag"
	"io"
	"koding/db/mongodb"
	"koding/db/mongodb/modelhelper"
	"koding/tools/config"
	"koding/tools/logger"
	"net"
	"net/http"
	"strconv"

	"github.com/gorilla/mux"
)

type ProxyPostMessage struct {
	Name          string
	Username      string
	Domain        string
	Persistence   string
	Mode          string
	Key           string
	RabbitKey     string
	Host          string
	HostnameAlias string
	FullUrl       string
	Hostdata      string
}

var flagProfile = flag.String("c", "", "Configuration profile from file")
var flagDebug = flag.Bool("d", false, "Debug mode")
var conf *config.Config
var log = logger.New("kontrolapi")

func main() {
	flag.Parse()
	if *flagProfile == "" {
		log.Fatal("Please define config file with -c")
	}

	rout := mux.NewRouter()
	rout.HandleFunc("/", home).Methods("GET")

	// Deployment handlers
	deployments := rout.PathPrefix("/deployments").Subrouter()
	deployments.HandleFunc("/", changeHandler(GetClients)).Methods("GET")
	deployments.HandleFunc("/", changeHandler(CreateClient)).Methods("POST")
	deployments.HandleFunc("/{build}", changeHandler(GetClient)).Methods("GET")
	deployments.HandleFunc("/{build}", changeHandler(DeleteClient)).Methods("DELETE")

	// Worker handlers
	workers := rout.PathPrefix("/workers").Subrouter()
	workers.HandleFunc("/", changeHandler(GetWorkers)).Methods("GET")
	workers.HandleFunc("/{uuid}", changeHandler(GetWorker)).Methods("GET")
	workers.HandleFunc("/url/{workername}", changeHandler(GetWorkerURL)).Methods("GET")

	// Proxy handlers
	proxies := rout.PathPrefix("/proxies").Subrouter()
	proxies.HandleFunc("/", changeHandler(GetProxies)).Methods("GET")
	proxies.HandleFunc("/{proxyname}", changeHandler(GetProxy)).Methods("GET")
	proxies.HandleFunc("/{proxyname}", changeHandler(CreateProxy)).Methods("POST")
	proxies.HandleFunc("/{proxyname}", changeHandler(DeleteProxy)).Methods("DELETE")

	// Service handlers
	services := rout.PathPrefix("/services").Subrouter()
	services.HandleFunc("/", changeHandler(GetUsers)).Methods("GET")
	services.HandleFunc("/{username}", changeHandler(GetServices)).Methods("GET")
	services.HandleFunc("/{username}", changeHandler(DeleteServices)).Methods("DELETE")
	services.HandleFunc("/{username}/{servicename}", changeHandler(GetService)).Methods("GET")
	services.HandleFunc("/{username}/{servicename}", changeHandler(DeleteService)).Methods("DELETE")
	services.HandleFunc("/{username}/{servicename}/{key}", changeHandler(GetKey)).Methods("GET")
	services.HandleFunc("/{username}/{servicename}/{key}", changeHandler(CreateKey)).Methods("POST")
	services.HandleFunc("/{username}/{servicename}/{key}", changeHandler(DeleteKey)).Methods("DELETE")

	// Domain handlers
	domains := rout.PathPrefix("/domains").Subrouter()
	domains.HandleFunc("/", changeHandler(GetDomains)).Methods("GET")
	domains.HandleFunc("/{domain}", changeHandler(GetDomain)).Methods("GET")
	domains.HandleFunc("/{domain}/resolv", changeHandler(ResolveDomain)).Methods("GET")
	domains.HandleFunc("/{domain}", changeHandler(CreateOrUpdateDomain)).Methods("POST", "PUT")
	domains.HandleFunc("/{domain}", changeHandler(DeleteDomain)).Methods("DELETE")

	// Restriction/Rule handlers
	restrictions := rout.PathPrefix("/restrictions").Subrouter()
	restrictions.HandleFunc("/", changeHandler(GetRestrictions)).Methods("GET")
	restrictions.HandleFunc("/{domain}", changeHandler(GetRestrictionByDomain)).Methods("GET")
	restrictions.HandleFunc("/{domain}", changeHandler(DeleteRestriction)).Methods("DELETE")
	restrictions.HandleFunc("/{domain}/{name}", changeHandler(CreateRuleByName)).Methods("POST", "PUT")
	restrictions.HandleFunc("/{domain}/{name}", changeHandler(DeleteRuleByName)).Methods("DELETE")

	// Filter handlers
	filters := rout.PathPrefix("/filters").Subrouter()
	filters.HandleFunc("/", changeHandler(GetFilters)).Methods("GET")
	filters.HandleFunc("/", changeHandler(CreateFilterByName)).Methods("POST")
	filters.HandleFunc("/{name}", changeHandler(GetFilterByName)).Methods("GET")
	filters.HandleFunc("/{name}", changeHandler(DeleteFilterByName)).Methods("DELETE")

	// Statistics handlers
	stats := rout.PathPrefix("/stats").Subrouter()
	stats.HandleFunc("/domains", changeHandler(GetDomainStats)).Methods("GET")
	stats.HandleFunc("/domains/{domain}", changeHandler(GetDomainStat)).Methods("GET")
	stats.HandleFunc("/domains/{domain}", changeHandler(DeleteDomainStat)).Methods("DELETE")
	stats.HandleFunc("/proxies", changeHandler(GetProxyStats)).Methods("GET")
	stats.HandleFunc("/proxies/{proxy}", changeHandler(GetProxyStat)).Methods("GET")
	stats.HandleFunc("/proxies/{proxy}", changeHandler(DeleteProxyStat)).Methods("DELETE")

	conf = config.MustConfig(*flagProfile)

	var logLevel logger.Level
	if *flagDebug {
		logLevel = logger.DEBUG
	} else {
		logLevel = logger.GetLoggingLevelFromConfig("kontrolapi", *flagProfile)
	}
	log.SetLevel(logLevel)

	kontrolDB = mongodb.NewMongoDB(conf.MongoKontrol)
	modelhelper.Initialize(conf.Mongo)

	port := strconv.Itoa(conf.Kontrold.Api.Port)
	log.Info("kontrol api is started. serving at :%s ...", port)

	http.Handle("/", rout)
	err := http.ListenAndServe(":"+port, nil)
	if err != nil {
		log.Error(err.Error())<commit_msg>kontrolapi: fix services path and print start log<commit_after>package main

import (
	"flag"
	"fmt"
	"io"
	"koding/db/mongodb"
	"koding/db/mongodb/modelhelper"
	"koding/tools/config"
	"koding/tools/logger"
	"net"
	"net/http"
	"strconv"

	"github.com/gorilla/mux"
)

type ProxyPostMessage struct {
	Name          string
	Username      string
	Domain        string
	Persistence   string
	Mode          string
	Key           string
	RabbitKey     string
	Host          string
	HostnameAlias string
	FullUrl       string
	Hostdata      string
}

var flagProfile = flag.String("c", "", "Configuration profile from file")
var flagDebug = flag.Bool("d", false, "Debug mode")
var conf *config.Config
var log = logger.New("kontrolapi")

func main() {
	flag.Parse()
	if *flagProfile == "" {
		log.Fatal("Please define config file with -c")
	}

	rout := mux.NewRouter()
	rout.HandleFunc("/", home).Methods("GET")

	// Deployment handlers
	deployments := rout.PathPrefix("/deployments").Subrouter()
	deployments.HandleFunc("/", changeHandler(GetClients)).Methods("GET")
	deployments.HandleFunc("/", changeHandler(CreateClient)).Methods("POST")
	deployments.HandleFunc("/{build}", changeHandler(GetClient)).Methods("GET")
	deployments.HandleFunc("/{build}", changeHandler(DeleteClient)).Methods("DELETE")

	// Worker handlers
	workers := rout.PathPrefix("/workers").Subrouter()
	workers.HandleFunc("/", changeHandler(GetWorkers)).Methods("GET")
	workers.HandleFunc("/{uuid}", changeHandler(GetWorker)).Methods("GET")
	workers.HandleFunc("/url/{workername}", changeHandler(GetWorkerURL)).Methods("GET")

	// Proxy handlers
	proxies := rout.PathPrefix("/proxies").Subrouter()
	proxies.HandleFunc("/", changeHandler(GetProxies)).Methods("GET")
	proxies.HandleFunc("/{proxyname}", changeHandler(GetProxy)).Methods("GET")
	proxies.HandleFunc("/{proxyname}", changeHandler(CreateProxy)).Methods("POST")
	proxies.HandleFunc("/{proxyname}", changeHandler(DeleteProxy)).Methods("DELETE")

	// Service handlers
	services := rout.PathPrefix("/services").Subrouter()
	services.HandleFunc("/", changeHandler(GetUsers)).Methods("GET")
	services.HandleFunc("/{username}/", changeHandler(GetServices)).Methods("GET")
	services.HandleFunc("/{username}/", changeHandler(DeleteServices)).Methods("DELETE")
	services.HandleFunc("/{username}/{servicename}", changeHandler(GetService)).Methods("GET")
	services.HandleFunc("/{username}/{servicename}", changeHandler(DeleteService)).Methods("DELETE")
	services.HandleFunc("/{username}/{servicename}/{key}", changeHandler(GetKey)).Methods("GET")
	services.HandleFunc("/{username}/{servicename}/{key}", changeHandler(CreateKey)).Methods("POST")
	services.HandleFunc("/{username}/{servicename}/{key}", changeHandler(DeleteKey)).Methods("DELETE")

	// Domain handlers
	domains := rout.PathPrefix("/domains").Subrouter()
	domains.HandleFunc("/", changeHandler(GetDomains)).Methods("GET")
	domains.HandleFunc("/{domain}", changeHandler(GetDomain)).Methods("GET")
	domains.HandleFunc("/{domain}/resolv", changeHandler(ResolveDomain)).Methods("GET")
	domains.HandleFunc("/{domain}", changeHandler(CreateOrUpdateDomain)).Methods("POST", "PUT")
	domains.HandleFunc("/{domain}", changeHandler(DeleteDomain)).Methods("DELETE")

	// Restriction/Rule handlers
	restrictions := rout.PathPrefix("/restrictions").Subrouter()
	restrictions.HandleFunc("/", changeHandler(GetRestrictions)).Methods("GET")
	restrictions.HandleFunc("/{domain}", changeHandler(GetRestrictionByDomain)).Methods("GET")
	restrictions.HandleFunc("/{domain}", changeHandler(DeleteRestriction)).Methods("DELETE")
	restrictions.HandleFunc("/{domain}/{name}", changeHandler(CreateRuleByName)).Methods("POST", "PUT")
	restrictions.HandleFunc("/{domain}/{name}", changeHandler(DeleteRuleByName)).Methods("DELETE")

	// Filter handlers
	filters := rout.PathPrefix("/filters").Subrouter()
	filters.HandleFunc("/", changeHandler(GetFilters)).Methods("GET")
	filters.HandleFunc("/", changeHandler(CreateFilterByName)).Methods("POST")
	filters.HandleFunc("/{name}", changeHandler(GetFilterByName)).Methods("GET")
	filters.HandleFunc("/{name}", changeHandler(DeleteFilterByName)).Methods("DELETE")

	// Statistics handlers
	stats := rout.PathPrefix("/stats").Subrouter()
	stats.HandleFunc("/domains", changeHandler(GetDomainStats)).Methods("GET")
	stats.HandleFunc("/domains/{domain}", changeHandler(GetDomainStat)).Methods("GET")
	stats.HandleFunc("/domains/{domain}", changeHandler(DeleteDomainStat)).Methods("DELETE")
	stats.HandleFunc("/proxies", changeHandler(GetProxyStats)).Methods("GET")
	stats.HandleFunc("/proxies/{proxy}", changeHandler(GetProxyStat)).Methods("GET")
	stats.HandleFunc("/proxies/{proxy}", changeHandler(DeleteProxyStat)).Methods("DELETE")

	conf = config.MustConfig(*flagProfile)

	var logLevel logger.Level
	if *flagDebug {
		logLevel = logger.DEBUG
	} else {
		logLevel = logger.GetLoggingLevelFromConfig("kontrolapi", *flagProfile)
	}
	log.SetLevel(logLevel)

	kontrolDB = mongodb.NewMongoDB(conf.MongoKontrol)
	modelhelper.Initialize(conf.Mongo)

	port := strconv.Itoa(conf.Kontrold.Api.Port)
	log.Info("kontrol api is started. serving at :%s ...", port)
	fmt.Printf("Kontrolapi started at port: %s\n", port)

	http.Handle("/", rout)
	err := http.ListenAndServe(":"+port, nil)
	if err != nil {
		log.Error(err.Error())
{'fraction_non_alphanumeric': 0.17898240608654303, 'fraction_numerical': 0.0, 'mean_word_length': 6.7266715650257165, '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': '4618249', 'n_tokens_mistral': 3204, 'n_tokens_neox': 3114, 'n_words': 453}