handlers

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 49 Imported by: 0 modules, 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

internal/api/handlers/component.go

Index

Constants

View Source
const (
	// RegistrationDisabled refuses self-registration: accounts are created
	// by an admin (POST /admin/users), the configuration (admin.*) or the
	// `gohead admin create` command.
	RegistrationDisabled = "disabled"
	// RegistrationOpen lets anyone create an account with the
	// DefaultRegistrationRole.
	RegistrationOpen = "open"
)

Registration modes for POST /auth/register.

View Source
const DefaultRegistrationRole = "viewer"

DefaultRegistrationRole is the role given to self-registered accounts.

Variables

View Source
var (
	ListItemRevisions        = listHistory(itemTarget)
	GetItemRevision          = getHistoryRevision(itemTarget)
	RestoreItemRevision      = restoreHistoryRevision(itemTarget)
	ListSingletonRevisions   = listHistory(singletonTarget)
	GetSingletonRevision     = getHistoryRevision(singletonTarget)
	RestoreSingletonRevision = restoreHistoryRevision(singletonTarget)
)

Item and singleton history routes.

View Source
var APIVersion = "dev"

APIVersion is reported in the OpenAPI document (set at startup).

View Source
var MediaPolicy = storage.UploadPolicy{MaxSize: 50 << 20}

MediaPolicy limits uploads; set at startup from the media configuration.

View Source
var Registration = RegistrationDisabled

Registration is the current registration mode, set at startup from auth.registration.

View Source
var SSOSettings struct {
	PublicURL string
	UIURL     string
}

SSOSettings are where GoHead and its admin UI are, as browsers reach them. Empty: from the request (GoHead serves its UI itself).

View Source
var SchemaNotifier interface {
	Notify(ctx context.Context) error
}

SchemaNotifier tells other API replicas that the schema changed. It is set at startup (see cmd/start.go); nil means single-replica mode.

Functions

func APIDocs added in v0.5.0

func APIDocs(public bool) gin.HandlerFunc

APIDocs serves Swagger UI for /api/openapi.json. When the spec needs a token, the page asks for one and keeps it for the browser session only.

func AfterDemoReset added in v0.8.0

func AfterDemoReset()

AfterDemoReset rebuilds what depends on the content model.

func AgentFunctionCatalog added in v0.5.0

func AgentFunctionCatalog(c *gin.Context)

AgentFunctionCatalog lists the built-in functions agents can use.

func ApproveProposal added in v0.6.0

func ApproveProposal(c *gin.Context)

ApproveProposal applies a proposal. Body (optional): {"data": {…}} to apply edited values instead of the agent's, {"force": true} to apply it although the item changed since. The change needs the caller's own permissions (publish to change a published item, create in the collections a relation object would create items in).

func CreateAPIToken added in v0.5.0

func CreateAPIToken(c *gin.Context)

CreateAPIToken creates a token and returns its secret once: {"name": "website", "role": "viewer", "expires_in_days": 90}.

func CreateAgent

func CreateAgent(c *gin.Context)

CreateAgent handles creating a new agent.

func CreateCollection

func CreateCollection(c *gin.Context)

CreateCollection handles creating a new collection.

func CreateComponent

func CreateComponent(c *gin.Context)

CreateComponentHandler creates a new component definition.

func CreateConnection added in v0.7.0

func CreateConnection(c *gin.Context)

CreateConnection adds a connection and lists its tools.

func CreateLocale added in v0.5.0

func CreateLocale(c *gin.Context)

CreateLocale adds a locale (admin).

func CreateOrUpdateSingleton

func CreateOrUpdateSingleton(c *gin.Context)

CreateOrUpdateSingleton handles the creation or updating of a single type.

func CreateOrUpdateSingletonItem

func CreateOrUpdateSingletonItem(c *gin.Context)

CreateOrUpdateSingletonItem creates or replaces a singleton's content. Requires the update permission.

func CreateRole added in v0.5.0

func CreateRole(c *gin.Context)

CreateRole adds a custom role (admin).

func CreateUser

func CreateUser(c *gin.Context)

CreateUser lets an admin create an account with any existing role.

func CreateWebhook added in v0.5.0

func CreateWebhook(c *gin.Context)

CreateWebhook registers a webhook. The signing secret is returned once.

func DeleteAgent

func DeleteAgent(c *gin.Context)

DeleteAgent handles deleting an agent by its name.

func DeleteCollection

func DeleteCollection(c *gin.Context)

DeleteCollectionByIDHandler handles deleting a collection by its ID.

func DeleteComponent

func DeleteComponent(c *gin.Context)

DeleteComponentHandler deletes a component by name.

func DeleteConnection added in v0.7.0

func DeleteConnection(c *gin.Context)

DeleteConnection removes a connection. Agents that use its tools get an error when they call them.

func DeleteItem

func DeleteItem(ct models.Collection) gin.HandlerFunc

func DeleteLocale added in v0.5.0

func DeleteLocale(c *gin.Context)

DeleteLocale removes a locale (admin). Content in it is deleted with ?purge=true; without it the request fails with 409 when there is some.

func DeleteMedia added in v0.4.0

func DeleteMedia(c *gin.Context)

DeleteMedia removes a file and its content. Requires the delete permission.

func DeleteRole added in v0.5.0

func DeleteRole(c *gin.Context)

DeleteRole removes a custom role no account or token uses (admin).

func DeleteSingleton

func DeleteSingleton(c *gin.Context)

DeleteSingleton handles deleting a single type by its name (optional).

func DeleteUser

func DeleteUser(c *gin.Context)

DeleteUser handles deleting a user.

func DeleteWebhook added in v0.5.0

func DeleteWebhook(c *gin.Context)

DeleteWebhook removes a webhook and its delivery log.

func DemoInfo added in v0.8.0

func DemoInfo(c *gin.Context)

DemoInfo tells the login page how to sign in to a public demo (404 when the instance is not a demo).

func DemoStatus added in v0.8.0

func DemoStatus(c *gin.Context)

DemoStatus returns the demo's settings and its snapshot.

func DynamicCollectionHandler

func DynamicCollectionHandler(c *gin.Context)

DynamicCollectionHandler handles CRUD operations for dynamic collections.

func GetAPIToken added in v0.5.0

func GetAPIToken(c *gin.Context)

GetAPIToken returns one token.

func GetAgent

func GetAgent(c *gin.Context)

func GetAgentRun added in v0.5.0

func GetAgentRun(c *gin.Context)

GetAgentRun returns one run with its steps.

func GetAgentUsage added in v0.5.0

func GetAgentUsage(c *gin.Context)

GetAgentUsage reports an agent's usage over the last hour and day next to its limits.

func GetAgents

func GetAgents(c *gin.Context)

GetAgents retrieves a list of agents with optional filtering and pagination.

func GetAllUsers

func GetAllUsers(c *gin.Context)

GetAllUsers handles fetching all users.

func GetCollection

func GetCollection(c *gin.Context)

func GetCollections

func GetCollections(c *gin.Context)

GetCollections retrieves a list of collections with optional filtering, sorting, and pagination.

func GetComponent

func GetComponent(c *gin.Context)

GetComponentHandler retrieves a component by name.

func GetComponents

func GetComponents(c *gin.Context)

GetComponents lists all component definitions.

func GetConnection added in v0.7.0

func GetConnection(c *gin.Context)

GetConnection returns a connection with its tools.

func GetItemByID

func GetItemByID(ct models.Collection, id uint, rc readContext) gin.HandlerFunc

GetItemByID retrieves a single item by ID.

func GetItems

func GetItems(collection models.Collection, rc readContext) gin.HandlerFunc

GetItems lists a collection's items with pagination, filtering and sorting.

Query parameters:

page, pageSize                 pagination (pageSize max 100)
filters[<field>][<op>]=<value> op: $eq $ne $lt $lte $gt $gte $contains
filters[<field>]=<value>       shorthand for $eq
sort=<field>[:asc|:desc],...   multiple keys allowed
status=published|draft|all     draft-and-publish collections (default published)

<field> is a collection attribute or one of id, createdAt, updatedAt, publishedAt (snake_case also accepted).

func GetMedia added in v0.4.0

func GetMedia(c *gin.Context)

GetMedia returns one media file. Requires the media read permission, like ListMedia.

func GetOverview added in v0.5.0

func GetOverview(c *gin.Context)

GetOverview returns counts and recent activity for the admin dashboard.

func GetProposal added in v0.6.0

func GetProposal(c *gin.Context)

GetProposal returns a proposal with the item as it is now, the values approving it would write ("proposed": for a stale update, the item now with the agent's changes) and the changes between the two.

func GetRole added in v0.5.0

func GetRole(c *gin.Context)

GetRole returns one role (admin).

func GetSingleItem

func GetSingleItem(c *gin.Context)

GetSingleItem returns a singleton's content in the flat item shape, with relations populated down to "level" (default 1).

func GetSingleton

func GetSingleton(c *gin.Context)

GetSingleton retrieves a single type by its name.

func GetSingletons

func GetSingletons(c *gin.Context)

GetSingletons lists all singleton definitions.

func GetUser

func GetUser(c *gin.Context)

GetUser handles fetching a single user by ID.

func GetWebhook added in v0.5.0

func GetWebhook(c *gin.Context)

GetWebhook returns one webhook.

func GraphQLHandler

func GraphQLHandler(c *gin.Context)

GraphQLHandler executes a GraphQL request. The caller's role is passed to resolvers through the context so that queries and mutations enforce the same permissions as the REST API.

func HandleWebhook

func HandleWebhook(c *gin.Context)

HandleWebhook is the Gin handler for incoming agent webhook requests.

func InitQueue added in v0.6.0

func InitQueue(client queue.Client)

InitQueue sets the queue client of the handlers.

func LinkSSOStart added in v0.8.0

func LinkSSOStart(c *gin.Context)

LinkSSOStart starts linking the signed-in account to a provider: it returns the URL to send the browser to (the start URL with a short-lived ticket, since a browser navigation carries no Authorization header).

func ListAPITokens added in v0.5.0

func ListAPITokens(c *gin.Context)

ListAPITokens lists tokens (never their secrets).

func ListAgentRuns added in v0.5.0

func ListAgentRuns(c *gin.Context)

ListAgentRuns lists an agent's runs, newest first: page, pageSize (≤ 100) and status (running, succeeded, failed, limited).

func ListAgentTemplates added in v0.6.0

func ListAgentTemplates(c *gin.Context)

ListAgentTemplates lists the ready-made agents and their parameters.

func ListAllAgentRuns added in v0.5.0

func ListAllAgentRuns(c *gin.Context)

ListAllAgentRuns lists the runs of every agent, newest first: page, pageSize (≤ 100) and status.

func ListConnectionPresets added in v0.7.0

func ListConnectionPresets(c *gin.Context)

ListConnectionPresets lists the services the admin UI offers to connect.

func ListConnections added in v0.7.0

func ListConnections(c *gin.Context)

ListConnections lists the connections.

func ListLocales added in v0.5.0

func ListLocales(c *gin.Context)

ListLocales lists the content locales, the default first. Any signed-in user can read them.

func ListMedia added in v0.4.0

func ListMedia(c *gin.Context)

ListMedia lists the media library: page, pageSize, mime (type prefix such as "image/") and search (file name). Browsing the library needs the media read permission (not given to viewers): it includes files only drafts use, so readers only reach files through the content that references them.

func ListProposals added in v0.6.0

func ListProposals(c *gin.Context)

ListProposals lists proposals, newest first: status (pending by default; approved, rejected, failed or all), collection, agent, agentRun, page, pageSize. Only collections the caller may change are listed.

func ListRevisions added in v0.5.0

func ListRevisions(c *gin.Context)

ListRevisions is the change feed across entries, newest first. Filters: collection, singleton, action, actorKind, actor, agentRun.

func ListRoles added in v0.5.0

func ListRoles(c *gin.Context)

ListRoles lists the roles with their permissions (admin).

func ListSSOProviders added in v0.8.0

func ListSSOProviders(c *gin.Context)

ListSSOProviders lists the providers people can sign in with.

func ListWebhookDeliveries added in v0.5.0

func ListWebhookDeliveries(c *gin.Context)

ListWebhookDeliveries returns the newest delivery attempts (limit ≤ 100).

func ListWebhooks added in v0.5.0

func ListWebhooks(c *gin.Context)

ListWebhooks lists webhooks.

func Login

func Login(c *gin.Context)

func Me added in v0.5.0

func Me(c *gin.Context)

Me returns the authenticated caller: a user, or an API token.

func OpenAPISpec added in v0.5.0

func OpenAPISpec(c *gin.Context)

OpenAPISpec serves the OpenAPI 3.1 description of the current content model. It is written directly (not wrapped in {"data": …}), as tools expect.

func PublishItem added in v0.4.0

func PublishItem(publish bool) gin.HandlerFunc

PublishItem publishes (publish=true) or unpublishes an item of a draft-and-publish collection: POST /api/collections/:collection/:id/publish and /unpublish. Requires the update permission.

func RefreshConnection added in v0.7.0

func RefreshConnection(c *gin.Context)

RefreshConnection lists a connection's tools again.

func Register

func Register(c *gin.Context)

Register creates a new account through the public endpoint, when registration is open. The caller never chooses its role: accounts get the least-privileged DefaultRegistrationRole, and admins promote users through PUT /admin/users/:id. No account is ever made admin here.

func RejectProposal added in v0.6.0

func RejectProposal(c *gin.Context)

RejectProposal discards a proposal. Body (optional): {"note": "…"}.

func RenderAgentTemplate added in v0.6.0

func RenderAgentTemplate(c *gin.Context)

RenderAgentTemplate builds an agent definition from a template. Body: {"params": {…}}. The definition is not saved: review it, then create it with POST /admin/agents.

func ResetDemo added in v0.8.0

func ResetDemo(c *gin.Context)

ResetDemo restores the snapshot now.

func RevertAgentRun added in v0.5.0

func RevertAgentRun(c *gin.Context)

RevertAgentRun undoes the content changes of one of an agent's runs. Entries changed by someone else since are skipped unless ?force=true.

func RevokeAPIToken added in v0.5.0

func RevokeAPIToken(c *gin.Context)

RevokeAPIToken revokes a token immediately.

func RunAgentNow added in v0.5.0

func RunAgentNow(c *gin.Context)

RunAgentNow queues a manual run of an agent, with an optional "input" message. The run appears in the agent's run history.

func SSOCallback added in v0.8.0

func SSOCallback(c *gin.Context)

SSOCallback finishes the sign-in and sends the browser back to the admin UI with a token, or with the reason it failed.

func ServeLocalMedia added in v0.4.0

func ServeLocalMedia(store *media.Local) gin.HandlerFunc

ServeLocalMedia serves files of the local driver under /uploads/<key>. Only files recorded in the media library are served, with their detected type, and with headers that stop browsers from running anything in them.

func StartSSO added in v0.8.0

func StartSSO(c *gin.Context)

StartSSO sends the browser to the provider. Query: bind (a random value the admin UI keeps, required), return (the admin UI path to open after signing in), link (a ticket from LinkSSOStart).

func TakeDemoSnapshot added in v0.8.0

func TakeDemoSnapshot(c *gin.Context)

TakeDemoSnapshot saves the database as it is now: the nightly reset goes back to it.

func TestAgent added in v0.6.0

func TestAgent(c *gin.Context)

TestAgent queues a test run (dry run): the agent runs for real (model calls, reads), but content functions only validate and report the changes they would make. Body: {"input": "…"} for a manual message, or {"item_id": 42, "event": "item:created"} to simulate the agent's collection event on an existing item.

func TestWebhook added in v0.5.0

func TestWebhook(c *gin.Context)

TestWebhook sends a "webhook:test" event right away and reports the outcome, so the URL, headers and signature can be checked from the admin.

func UnlinkUserSSO added in v0.8.0

func UnlinkUserSSO(c *gin.Context)

UnlinkUserSSO removes a user's link to their identity provider (admin): they sign in with their password again.

func UpdateAgent

func UpdateAgent(c *gin.Context)

UpdateAgent handles updating an existing agent.

func UpdateCollection

func UpdateCollection(c *gin.Context)

UpdateCollection handles updating an existing collection.

func UpdateComponent

func UpdateComponent(c *gin.Context)

UpdateComponentHandler updates an existing component definition.

func UpdateConnection added in v0.7.0

func UpdateConnection(c *gin.Context)

UpdateConnection changes a connection and lists its tools again.

func UpdateItem

func UpdateItem(collection models.Collection) gin.HandlerFunc

UpdateItem replaces an item's data. The body's optional "status" publishes or unpublishes it in draft-and-publish collections.

func UpdateLocale added in v0.5.0

func UpdateLocale(c *gin.Context)

UpdateLocale renames a locale, and makes it the default with {"isDefault": true} (admin).

func UpdateMedia added in v0.4.0

func UpdateMedia(c *gin.Context)

UpdateMedia changes a file's name, alt text or caption: {"data": {"alt": "…"}}. Requires the update permission.

func UpdateRole added in v0.5.0

func UpdateRole(c *gin.Context)

UpdateRole replaces a custom role's description and permissions (admin).

func UpdateUser

func UpdateUser(c *gin.Context)

UpdateUser lets an admin change a user's username, email, password or role. Unknown fields are rejected so that arbitrary columns cannot be written.

func UpdateWebhook added in v0.5.0

func UpdateWebhook(c *gin.Context)

UpdateWebhook changes a webhook; "rotate_secret": true issues a new secret.

func UploadMedia added in v0.4.0

func UploadMedia(c *gin.Context)

UploadMedia stores the files of a multipart/form-data request (fields "files" or "file"; optional "alt" and "caption"). Requires the create permission. All files are stored, or none.

Types

type LoginAttemptGuard

type LoginAttemptGuard struct {
	Counter     ratelimit.Counter
	MaxFailures int
	Window      time.Duration
}

LoginAttemptGuard limits failed logins per (username, client IP) within a window. Keying on both stops password guessing against an account without letting anyone lock a user out from another address.

var LoginGuard *LoginAttemptGuard

LoginGuard is set at startup; nil disables the check.

Jump to

Keyboard shortcuts

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