controller

package
v0.0.0-...-c2a27a2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxRecordLimit = 1000
)

Variables

View Source
var (
	// Errors
	ErrorRecordNotFound = errors.New("record not found")
)
View Source
var Routes = []Route{
	Route{
		GetRecord,
		http.MethodGet,
		"/records/:id",
		[]server.ResponseSetting{},
	},
	Route{
		FindRecords,
		http.MethodGet,
		"/records",
		[]server.ResponseSetting{},
	},
}

Routes is a list of Indexer server routes

View Source
var V1 = func() Controller {
	controllerOnce.Do(func() {
		var cfg Config
		if err := config.Load(&cfg); err != nil {
			panic(err)
		}
		ctx := context.Background()
		db, err := cdxjdb.New(
			ctx,
			cfg.DatabaseAddr,
			cfg.DropDatabaseOnStart,
		)
		if err != nil {
			panic(fmt.Errorf(
				"Controller: failed to connect to database at "+
					"address ('%s') with error: %s",
				cfg.DatabaseAddr, err,
			))
		}
		control = New(ctx, db)
	})
	return control
}

Functions

func FindRecords

func FindRecords(w http.ResponseWriter, r *http.Request, p server.Parameters)

FindRecords handles a request to find CDXJ records matching a given set of values

func GetRecord

func GetRecord(w http.ResponseWriter, r *http.Request, p server.Parameters)

GetRecord handles requests to retrieve a CDXJ record matching a given ID

Types

type Config

type Config struct {
	DatabaseAddr        string `toml:"database_addr"`
	DropDatabaseOnStart bool   `toml:"drop_database_on_start"`
}

Config represents the configuration of an Indexer controller

type Controller

type Controller interface {
	// FindRecords searches for records that match the given values and returns
	// a list of matching records
	FindRecords(
		surt string,
		types []simplecdxj.RecordType,
		before, after string,
		match models.TextMatch,
		limit int,
	) (models.Records, error)

	// GetRecord returns the record for the given record ID
	GetRecord(id string) (models.Record, error)
}

Controller represents an interface of an WARC-CDXJ record indexer's controller

func New

New returns a new Controller

type Route

type Route struct {
	Handler          server.Handler
	Method           string
	Path             string
	ResponseSettings []server.ResponseSetting
}

Route represents an Indexer server route

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL