webserver

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package webserver is the optional cryptolab web console backend: a self-contained HTTP server that stages uploaded files, runs a selected cryptolab tool/mode with form-supplied settings, streams progress, and returns the structured Result and any artifacts. It is the browser counterpart to the `cryptolab` CLI.

It is imported only by the tag-gated `cryptolab serve` command, so it is never linked into the default gophertrunk binary. It depends only on the cryptolab engine package and the standard library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Assets is the embedded SPA file system (served at /). Nil serves the
	// API only with a short placeholder at /.
	Assets fs.FS
	// TempDir stages uploads and job artifacts. Empty ⇒ a fresh temp dir the
	// server owns and removes on Close.
	TempDir string
	// MaxUploadBytes bounds one upload. 0 ⇒ 512 MiB.
	MaxUploadBytes int64
	// Logger receives server-level logs. Nil ⇒ slog.Default.
	Logger *slog.Logger
}

Options configure a Server.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the cryptolab web console HTTP handler.

func New

func New(opts Options) (*Server, error)

New constructs a Server. The staging temp directory is created lazily on the first upload/run (not at construction), so merely registering the routes — as the daemon does for every request mux — costs nothing on disk.

func (*Server) Close

func (s *Server) Close() error

Close removes the temp directory if the server created it.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns a standalone HTTP mux: the cryptolab API plus the embedded SPA at /. Used by `cryptolab serve`.

func (*Server) RegisterAPI

func (s *Server) RegisterAPI(mux *http.ServeMux, gate func(http.HandlerFunc) http.HandlerFunc)

RegisterAPI mounts the /api/v1/cryptolab/* routes onto mux. Mutating routes (file upload, run) are wrapped with gate when non-nil, so the daemon can apply the same auth middleware it uses for its other write routes; the standalone server passes nil. This lets the same service back both the standalone `cryptolab serve` and the daemon-mounted console at /cryptolab/.

Jump to

Keyboard shortcuts

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