<commit_before>package accounts

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

	"github.com/gorilla/mux"

	"github.com/mrvdot/golang-utils"

	"appengine"
)

var (
	// Router instance for accounts, made public to allow for adding additional routes
	Router        *mux.Router
	SubrouterPath = "accounts"
)

// func InitRouter attaches two routes "new" and "authenticate" to a subpath
// to the http handler
// If an empty string is passed for the subpath, the default SubrouterPath is used
func InitRouter(subpath string) {
	if subpath == "" {
		subpath = SubrouterPath
	} else {
		SubrouterPath = subpath
	}
	Router = mux.NewRouter()
	ar := Router.PathPrefix(fmt.Sprintf("/%v", SubrouterPath)).Subrouter()
	ar.HandleFunc("/new", newAccount).
		Methods("POST").
		Name("CreateAccount")
	ar.HandleFunc("/authenticate", authenticate).
		Methods("POST").
		Name("Authenticate")
	http.Handle(fmt.Sprintf("/%v/", SubrouterPath), Router)
}

// func newAccount creates a new request based on the "account" parameter passed in
func newAccount(rw http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)
	out := json.NewEncoder(rw)
	response := &utils.ApiResponse{}
	name := req.FormValue("account")
	ctx.Infof("Creating new account for %v", name)
	if name == "" {
		response.Code = 400
		response.Message = "Account name must be provided"
		out.Encode(response)
		return
	}
	acct := &Account{
		Name:   name,
		Active: true,
	}
	_, err := utils.Save(ctx, acct)
	if err != nil {
		response.Code = 500
		response.Message = "Error saving new account: " + err.Error()
		out.Encode(response)
		return<commit_msg>Fixing accounts import<commit_after>package accounts

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

	"github.com/gorilla/mux"

	"github.com/mrvdot/appengine/aeutils"
	"github.com/mrvdot/golang-utils"

	"appengine"
)

var (
	// Router instance for accounts, made public to allow for adding additional routes
	Router        *mux.Router
	SubrouterPath = "accounts"
)

// func InitRouter attaches two routes "new" and "authenticate" to a subpath
// to the http handler
// If an empty string is passed for the subpath, the default SubrouterPath is used
func InitRouter(subpath string) {
	if subpath == "" {
		subpath = SubrouterPath
	} else {
		SubrouterPath = subpath
	}
	Router = mux.NewRouter()
	ar := Router.PathPrefix(fmt.Sprintf("/%v", SubrouterPath)).Subrouter()
	ar.HandleFunc("/new", newAccount).
		Methods("POST").
		Name("CreateAccount")
	ar.HandleFunc("/authenticate", authenticate).
		Methods("POST").
		Name("Authenticate")
	http.Handle(fmt.Sprintf("/%v/", SubrouterPath), Router)
}

// func newAccount creates a new request based on the "account" parameter passed in
func newAccount(rw http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)
	out := json.NewEncoder(rw)
	response := &utils.ApiResponse{}
	name := req.FormValue("account")
	ctx.Infof("Creating new account for %v", name)
	if name == "" {
		response.Code = 400
		response.Message = "Account name must be provided"
		out.Encode(response)
		return
	}
	acct := &Account{
		Name:   name,
		Active: true,
	}
	_, err := aeutils.Save(ctx, acct)
	if err != nil {
		response.Code = 500
		response.Message = "Error saving new account: " + err.Error()
		out.Encode(response)
		return
{'fraction_non_alphanumeric': 0.1340645947592931, 'fraction_numerical': 0.003656307129798903, 'mean_word_length': 4.105754276827372, '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': '1155955', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1077, 'n_words': 296}