Help us shape the future of Go! Take the 2026 Go Developer Survey

extaccountapi

package
v1.149.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package extaccountapi is the REST surface of external accounts (#2092): the admin routes that create, list, extend, suspend, resume and remove the accounts and edit their settings, and the two public routes a person signs in through, asking for a link and claiming it.

Index

Constants

View Source
const (

	// RequestPath is the public route a sign-in link is asked for on.
	RequestPath = "/portal/auth/email-link"
)

Variables

This section is empty.

Functions

func RegisterAdmin

func RegisterAdmin(mux *http.ServeMux, wrap func(http.Handler) http.Handler, cfg Config)

RegisterAdmin mounts the admin routes behind wrap, the admin API's authentication.

func RegisterPublic

func RegisterPublic(mux *http.ServeMux, svc Service)

RegisterPublic mounts the routes a person signs in through. They take no authentication: asking for a link answers the same for every address, and a link is its own credential.

Types

type Config

type Config struct {
	Service  Service
	Settings SettingsStore
	// SharedItems counts the live shares to an address.
	SharedItems func(ctx context.Context, email string) (int, error)
	// Author resolves the acting admin.
	Author func(*http.Request) string
	// Now is the clock; nil is time.Now.
	Now func() time.Time
}

Config is what the routes are built from.

type ExtendRequest

type ExtendRequest struct {
	// ExpiresAt is the new expiry; null removes it.
	ExpiresAt *time.Time `json:"expires_at"`
}

ExtendRequest sets or clears an account's expiry.

type LinkRequest

type LinkRequest struct {
	Email string `json:"email" example:"client@example.org"`
}

LinkRequest asks for a sign-in link.

type Service

type Service interface {
	Create(ctx context.Context, n extaccount.NewAccount, by string) (extaccount.Account, error)
	List(ctx context.Context) ([]extaccount.Account, error)
	Extend(ctx context.Context, id string, expiresAt *time.Time) error
	Suspend(ctx context.Context, id string) error
	Resume(ctx context.Context, id string) error
	Remove(ctx context.Context, id string) error
	RequestLink(ctx context.Context, email string)
	Claim(ctx context.Context, w http.ResponseWriter, token string) (extaccount.Account, error)
}

Service is the account service the routes call.

type SettingsStore

type SettingsStore interface {
	Read(ctx context.Context) extaccount.Settings
	Write(ctx context.Context, s extaccount.Settings, author string) error
}

SettingsStore reads and writes the settings section.

type UserList

type UserList struct {
	Users []UserView `json:"users"`
}

UserList is the admin list.

type UserView

type UserView struct {
	extaccount.Account
	// Status is active, suspended, expired or converted.
	Status string `json:"status" example:"active"`
	// SharedItems is the live shares to the account's address.
	SharedItems int `json:"shared_items" example:"3"`
}

UserView is one external account as the admin list shows it.

Jump to

Keyboard shortcuts

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