<commit_before>package horizon

import (
	"github.com/rcrowley/go-metrics"
	"github.com/rs/cors"
	"github.com/zenazn/goji/web"
	"github.com/zenazn/goji/web/middleware"
)

type Web struct {
	router *web.Mux

	requestTimer metrics.Timer
	failureMeter metrics.Meter
	successMeter metrics.Meter
}

func NewWeb(app *App) (*Web, error) {

	api := web.New()
	result := Web{
		router:       api,
		requestTimer: metrics.NewTimer(),
		failureMeter: metrics.NewMeter(),
		successMeter: metrics.NewMeter(),
	}

	app.metrics.Register("requests.total", result.requestTimer)
	app.metrics.Register("requests.succeeded", result.successMeter)
	app.metrics.Register("requests.failed", result.failureMeter)

	installMiddleware(api, app)
	installActions(api)

	return &result, nil
}

func installMiddleware(api *web.Mux, app *App) {
	api.Use(middleware.RequestID)
	api.Use(middleware.Logger)
	api.Use(middleware.Recoverer)
	api.Use(middleware.AutomaticOptions)
	api.Use(appMiddleware(app))
	api.Use(requestMetricsMiddleware)

	c := cors.New(cors.Options{
		AllowedOrigins: []string{"*"},
	})
	api.Use(c.Handler)
}

func installActions(api *web.Mux) {
	api.Get("/", rootAction)
	api.Get("/metrics", metricsAction)
	api.Get("/ledgers", ledgerIndexAction)
	api.Get("/ledgers/:id", ledgerShowAction)
	api.Get("/stream", streamAction)

	api.NotFound(notFoundAction)
}<commit_msg>Rough in history api endpoints<commit_after>package horizon

import (
	"github.com/rcrowley/go-metrics"
	"github.com/rs/cors"
	"github.com/zenazn/goji/web"
	"github.com/zenazn/goji/web/middleware"
)

type Web struct {
	router *web.Mux

	requestTimer metrics.Timer
	failureMeter metrics.Meter
	successMeter metrics.Meter
}

func NewWeb(app *App) (*Web, error) {

	api := web.New()
	result := Web{
		router:       api,
		requestTimer: metrics.NewTimer(),
		failureMeter: metrics.NewMeter(),
		successMeter: metrics.NewMeter(),
	}

	app.metrics.Register("requests.total", result.requestTimer)
	app.metrics.Register("requests.succeeded", result.successMeter)
	app.metrics.Register("requests.failed", result.failureMeter)

	installMiddleware(api, app)
	installActions(api)

	return &result, nil
}

func installMiddleware(api *web.Mux, app *App) {
	api.Use(middleware.RequestID)
	api.Use(middleware.Logger)
	api.Use(middleware.Recoverer)
	api.Use(middleware.AutomaticOptions)
	api.Use(appMiddleware(app))
	api.Use(requestMetricsMiddleware)

	c := cors.New(cors.Options{
		AllowedOrigins: []string{"*"},
	})
	api.Use(c.Handler)
}

func installActions(api *web.Mux) {
	api.Get("/", rootAction)
	api.Get("/metrics", metricsAction)

	// ledger actions
	api.Get("/ledgers", ledgerIndexAction)
	api.Get("/ledgers/:id", ledgerShowAction)
	api.Get("/ledgers/:ledger_id/transactions", notFoundAction)
	api.Get("/ledgers/:ledger_id/operations", notFoundAction)
	api.Get("/ledgers/:ledger_id/effects", notFoundAction)

	// account actions
	api.Get("/accounts", notFoundAction)
	api.Get("/accounts/:id", notFoundAction)
	api.Get("/accounts/:account_id/transactions", notFoundAction)
	api.Get("/accounts/:account_id/operations", notFoundAction)
	api.Get("/accounts/:account_id/effects", notFoundAction)

	// transaction actions
	api.Get("/transactions", notFoundAction)
	api.Get("/transactions/:id", notFoundAction)
	api.Get("/transactions/:tx_id/operations", notFoundAction)
	api.Get("/transactions/:tx_id/effects", notFoundAction)

	// transaction actions
	api.Get("/operations", notFoundAction)
	api.Get("/operations/:id", notFoundAction)
	api.Get("/operations/:tx_id/effects", notFoundAction)

	api.Get("/stream", streamAction)

	api.NotFound(notFoundAction)
}
{'fraction_non_alphanumeric': 0.15393164767991108, 'fraction_numerical': 0.0, 'mean_word_length': 5.428571428571429, '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': '7494466', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1284, 'n_words': 196}