app

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 49 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package app is the Visoto server: it loads the configuration, the SPARQL preprocessor and the templates, registers every route and runs the HTTP server. cmd/visoto is a thin wrapper around Main; the commercial edition calls Main with its own plugins.

Index

Constants

View Source
const (
	ActionPublic   = access.Public
	ActionBrowse   = access.Browse
	ActionSPARQL   = access.SPARQL
	ActionUpload   = access.Upload
	ActionAdmin    = access.Admin
	ActionSignedIn = access.SignedIn
)

Variables

This section is empty.

Functions

func Main

func Main(plugins ...Plugin)

Main loads the configuration, initializes every subsystem, registers the routes and runs the server until it fails.

func RenderName

func RenderName(c *gin.Context, templateName string) string

RenderName maps a logical template name ("pages/account.html") onto the variant registered for the request's language, for plugin handlers that render one of the core's templates.

Types

type Access

type Access = access.Request

Access is one authorization decision: an Action on a store, optionally for one resource IRI.

type Action

type Action = access.Action

Action is what a route does with the store it addresses; see the constants.

type Authorizer

type Authorizer = access.Authorizer

Authorizer decides every guarded request. See access.Authorizer for the context contract: context.Background() means an anonymous caller.

type ChatCredentials added in v0.4.0

type ChatCredentials = chat.Credentials

ChatCredentials is an AI provider key a caller brings for the chat (UA-50); Provider is "anthropic".

type Denier

type Denier interface {
	Deny(c *gin.Context, r access.Request)
}

Denier is optionally implemented by an Authorizer that answers a refused request itself — a redirect to sign-in for an anonymous caller, say. It must write the response; c is aborted afterwards either way.

type Host

type Host struct {
	// ConfigPath is the visoto.config the server loaded; a plugin reads its own
	// section from it.
	ConfigPath string
	// DataDir is the directory for local state (SQLite files).
	DataDir string
	// contains filtered or unexported fields
}

Host is what a plugin gets to work with.

func TestHost added in v0.3.0

func TestHost(router *gin.Engine, configPath, dataDir string, stores ...Store) *Host

TestHost is a Host on a bare router, for testing a plugin against the real route guard and /_auth/check without the rest of the server. stores become the configured endpoints, the first one the default. It replaces the package's configuration and authorizer, so tests that use it must not run in parallel.

func (*Host) DecodeConfig added in v0.2.0

func (h *Host) DecodeConfig(v any) error

DecodeConfig decodes visoto.config into v, with the core's ${VAR} and .env expansion; a plugin declares only its own section, e.g. a struct with an `Accounts … toml:"accounts"` field.

func (*Host) Handle

func (h *Host) Handle(method, path string, action Action, handlers ...gin.HandlerFunc)

Handle registers a plugin route with the access it needs, through the same table and guard as the core routes.

func (*Host) Logger added in v0.2.0

func (h *Host) Logger() *slog.Logger

Logger is the server's structured logger.

func (*Host) RegisterCollector added in v0.2.0

func (h *Host) RegisterCollector(c prometheus.Collector)

RegisterCollector adds a Prometheus collector to /metrics.

func (*Host) SetAuthorizer

func (h *Host) SetAuthorizer(a Authorizer)

SetAuthorizer replaces the allow-all default. An Authorizer that also implements Denier answers refused requests itself.

func (*Host) SetChatCredentials added in v0.4.0

func (h *Host) SetChatCredentials(f func(ctx context.Context) (ChatCredentials, bool))

SetChatCredentials lets a plugin supply the caller's own AI key: when f returns an Anthropic key for the request's context, the chat answers with Claude on that key instead of the instance's Gemini key. f must never log or return a key to the browser.

func (*Host) Stores

func (h *Host) Stores() []Store

Stores lists the configured endpoints.

func (*Host) Use

func (h *Host) Use(mw ...gin.HandlerFunc)

Use adds middleware that runs on every route, before its guard — the place to put the caller's identity into the request context.

type Plugin

type Plugin interface {
	Init(h *Host) error
}

Plugin extends the server. Init runs once, after the configuration, the catalogs and the core middlewares are set up and before any core route is registered — so middleware a plugin adds applies to every route.

type Store

type Store struct {
	Slug    string
	Name    string
	Default bool
}

Store is a configured SPARQL endpoint as plugins see it. Its URL and credentials stay inside the core.

Jump to

Keyboard shortcuts

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