<commit_before>package main

import (
	"github.com/goji/httpauth"
	"github.com/nathan-osman/go-cannon/api"
	"github.com/nathan-osman/go-cannon/queue"
	"github.com/zenazn/goji"
	"github.com/zenazn/goji/bind"
	"github.com/zenazn/goji/web"

	"crypto/tls"
	"flag"
	"log"
	"net/http"
	"os"
)

// Global mail queue exposed to the API methods.
var q *queue.Queue

// Goji middleware to expose the mail queue to the API methods.
func queueMiddleware(c *web.C, h http.Handler) http.Handler {
	fn := func(w http.ResponseWriter, r *http.Request) {
		c.Env["queue"] = q
		h.ServeHTTP(w, r)
	}
	return http.HandlerFunc(fn)
}

func main() {

	// Storage for values supplied via command-line parameters
	var (
		tlsCert   string
		tlsKey    string
		username  string
		password  string
		directory string
	)

	// Set the default port, while still allowing for the usual overrides
	if s := bind.Sniff(); s == "" {
		flag.Lookup("bind").Value.Set(":8025")
		flag.Lookup("bind").DefValue = ":8025"
	}

	// Add command-line flags for each of the options and then parse them
	flag.StringVar(&tlsCert, "tls-cert", "", "certificate for TLS")
	flag.StringVar(&tlsKey, "tls-key", "", "private key for TLS")
	flag.StringVar(&username, "username", "", "username for HTTP basic auth")
	flag.StringVar(&password, "password", "", "password for HTTP basic auth")
	flag.StringVar(&directory, "directory", "", "directory for the mail queue")
	flag.Parse()

	// Create the mail queue
	var err error
	q, err = queue.NewQueue(directory)
	if err != nil {
		log.Println(err)
		os.Exit(1)
	}
	defer q.Stop()

	// Add the two current API methods
	goji.Get("/v1/version", api.Version)<commit_msg>Implemented default storage directory (#3).<commit_after>package main

import (
	"github.com/goji/httpauth"
	"github.com/mitchellh/go-homedir"
	"github.com/nathan-osman/go-cannon/api"
	"github.com/nathan-osman/go-cannon/queue"
	"github.com/zenazn/goji"
	"github.com/zenazn/goji/bind"
	"github.com/zenazn/goji/web"

	"crypto/tls"
	"flag"
	"log"
	"net/http"
	"os"
	"path"
)

// Global mail queue exposed to the API methods.
var q *queue.Queue

// Goji middleware to expose the mail queue to the API methods.
func queueMiddleware(c *web.C, h http.Handler) http.Handler {
	fn := func(w http.ResponseWriter, r *http.Request) {
		c.Env["queue"] = q
		h.ServeHTTP(w, r)
	}
	return http.HandlerFunc(fn)
}

func main() {

	// Storage for values supplied via command-line parameters
	var (
		tlsCert   string
		tlsKey    string
		username  string
		password  string
		directory string
	)

	// Set the default port, while still allowing for the usual overrides
	if s := bind.Sniff(); s == "" {
		flag.Lookup("bind").Value.Set(":8025")
		flag.Lookup("bind").DefValue = ":8025"
	}

	// Obtain the user's home directory
	home, err := homedir.Dir()
	if err != nil {
		log.Println(err)
		os.Exit(1)
	}
	directory = path.Join(home, ".go-cannon")

	// Add command-line flags for each of the options and then parse them
	flag.StringVar(&tlsCert, "tls-cert", "", "certificate for TLS")
	flag.StringVar(&tlsKey, "tls-key", "", "private key for TLS")
	flag.StringVar(&username, "username", "", "username for HTTP basic auth")
	flag.StringVar(&password, "password", "", "password for HTTP basic auth")
	flag.StringVar(&directory, "directory", directory, "directory for the mail queue")
	flag.Parse()

	// Create the mail queue
	q, err = queue.NewQueue(directory)
	if err != nil {
		log.Println(err)
		os.Exit(1)
	}
	defer q.Stop()

	// Add the two current API methods
	goji.Get("/v1/version", api.Version)
{'fraction_non_alphanumeric': 0.14867156585641605, 'fraction_numerical': 0.006218202374222725, 'mean_word_length': 3.7953929539295395, 'pattern_counts': {'":': 4, '<': 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': '2412367', 'n_tokens_mistral': 1306, 'n_tokens_neox': 1256, 'n_words': 341}