aepbase

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(opts ServerOptions) error

Run initializes the database, loads existing resources, registers custom methods, and starts the HTTP server. It blocks until the server exits.

Types

type CustomMethodConfig

type CustomMethodConfig struct {
	// HTTP method: "POST" or "GET".
	Method string
	// Request body schema (required for POST methods).
	RequestSchema *openapi.Schema
	// Response body schema (required).
	ResponseSchema *openapi.Schema
	// Handler is the HTTP handler for the custom method.
	// The request will have path values extracted for all parent IDs and the resource ID.
	Handler http.HandlerFunc
	// Async, when true, makes this a long-running operation.
	// The handler runs in the background and callers receive an Operation
	// resource (HTTP 202) that can be polled for completion.
	Async bool
}

CustomMethodConfig defines a custom method to register on a resource.

type CustomMethodOption

type CustomMethodOption struct {
	ResourceSingular string
	MethodName       string
	Method           string
	RequestSchema    *openapi.Schema
	ResponseSchema   *openapi.Schema
	Handler          func(*sql.DB) http.HandlerFunc
	// Async, when true, makes this a long-running operation.
	// The handler runs in the background and callers receive an Operation
	// resource (HTTP 202) that can be polled for completion.
	Async bool
}

CustomMethodOption defines a custom method to register on a resource. The Handler factory receives the initialized *sql.DB so handlers can access the database without needing it at configuration time.

type ServerOptions

type ServerOptions struct {
	Port     int
	DataDir  string
	DBFile   string
	InMemory bool
	// Defaults to ["https://ui.aep.dev"]. Setting this replaces the default.
	CORSAllowedOrigins []string
	// Turns CORS off entirely (no headers sent, default origin not added).
	DisableCORS     bool
	CustomMethods   []CustomMethodOption
	ExportResources bool
	// EnableFileFields turns on experimental support for file-field properties
	// on resources (schema extension x-aepbase-file-field: true). File fields
	// are NOT part of the AEP specification and this option is intentionally
	// library-only — it is not registered as a CLI flag, so `main.go` cannot
	// enable it. Off by default.
	EnableFileFields bool
	// EnableUsers turns on user authentication and authorization. When enabled,
	// all API requests (except login) require a valid Bearer token. A default
	// superuser is created on first run. This option is intentionally
	// library-only — it is not registered as a CLI flag. Off by default.
	EnableUsers bool
	// contains filtered or unexported fields
}

ServerOptions configures an aepbase server. Zero-value fields use sensible defaults (port 8080, DB "aepbase.db").

func (*ServerOptions) RegisterFlags

func (o *ServerOptions) RegisterFlags()

RegisterFlags registers CLI flags for the server options. If Port or DBPath are already set, their values are used as the flag defaults. Call flag.Parse() after this method.

type State

type State struct {
	API *api.API

	DB                 *sql.DB
	ServerURL          string
	CORSAllowedOrigins []string
	// contains filtered or unexported fields
}

func NewState

func NewState(d *sql.DB, serverURL string) *State

func (*State) AddCustomMethod

func (s *State) AddCustomMethod(resourceSingular, methodName string, config CustomMethodConfig) error

AddCustomMethod registers a custom method on a resource. The method will be available at /{resource_path}:{methodName}. If the resource does not exist yet, the registration is deferred and will be applied automatically when the resource is added.

func (*State) AddResource

func (s *State) AddResource(def meta.ResourceDefinition) error

func (*State) EnableFileFields

func (s *State) EnableFileFields(filesDir string)

EnableFileFields turns on experimental support for file-field properties on resources. filesDir is the on-disk directory where uploaded files are stored. This method is library-only; it is not exposed via CLI flags. Calling it multiple times is safe — later calls overwrite the directory.

func (*State) EnableUsers

func (s *State) EnableUsers() error

EnableUsers turns on user authentication and authorization. When enabled, all API requests (except login) require a valid Bearer token. If no users exist in the database, a default superuser is created and its credentials are logged to stdout. This method is library-only; it is not exposed via CLI flags.

func (*State) ExportUserResourcesOpenAPI

func (s *State) ExportUserResourcesOpenAPI() ([]byte, error)

ExportUserResourcesOpenAPI generates the OpenAPI spec filtered to only user-defined resources, excluding built-in endpoints like /aep-resource-definitions and /operations.

func (*State) FileFieldsEnabled

func (s *State) FileFieldsEnabled() bool

FileFieldsEnabled reports whether file-field support is turned on.

func (*State) GetAPI

func (s *State) GetAPI() *api.API

func (*State) GetDB

func (s *State) GetDB() *sql.DB

func (*State) Handler

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

func (*State) HasResource

func (s *State) HasResource(singular string) bool

HasResource reports whether a resource with the given singular name exists in the API (including built-in resources).

func (*State) RemoveResource

func (s *State) RemoveResource(singular string) error

func (*State) UpdateResourceSchema

func (s *State) UpdateResourceSchema(def meta.ResourceDefinition, oldDef meta.ResourceDefinition) error

func (*State) UsersEnabled

func (s *State) UsersEnabled() bool

UsersEnabled reports whether user support is turned on.

Jump to

Keyboard shortcuts

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