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

This section is empty.

Variables

View Source
var (
	// Errors
	ErrorReplayNotFound = errors.New("replay not found")
)
View Source
var Routes = []Route{
	Route{
		Replay,
		http.MethodGet,
		"/replays/:id",
		[]server.ResponseSetting{},
	},
}

Routes is a list of Replayer 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()
		extKey := []byte{}
		if cfg.EncryptionKey != "" {
			extKey = crypto.ExtendKey(
				[]byte(cfg.EncryptionKey),
				[]byte(cfg.EncryptionSalt),
			)
		}
		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,
			))
		}
		rpl, err := replayer.New(ctx, cfg.IpfsAddress, db)
		if err != nil {
			panic(err)
		}
		control = New(ctx, extKey, rpl)
	})
	return control
}

Functions

func Replay

Replay handles requests to retrieve a WARC replay for the given record Id

Types

type Config

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

	// Encyption configuraiton
	EncryptionKey  string `toml:"encryption_key"`
	EncryptionSalt string `toml:"encryption_salt"`

	// IPFS configuration
	IpfsAddress string `toml:"ipfs_address"`
}

Config represents the configuration of a Replayer's controller

type Controller

type Controller interface {
	// Replay returns a WARC replay for the given record Id
	Replay(id string) (models.Replay, error)
}

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

func New

func New(ctx context.Context, key []byte, rpl replayer.Replayer) Controller

New returns a new Controller

type Route

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

Route represents an Replayer server route

Jump to

Keyboard shortcuts

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