resource

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: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(d *sql.DB, plural string, path string) (bool, error)

func Insert

func Insert(d *sql.DB, plural string, r *StoredResource, parentIDs map[string]string, schema *openapi.Schema) error

func MakeDownloadHandler

func MakeDownloadHandler(d *sql.DB, r *api.Resource, fileFields map[string]bool, filesDir string) http.HandlerFunc

MakeDownloadHandler returns an HTTP handler for the :download custom method. Clients POST a JSON body {"field": "<name>"} naming a file field on the resource identified by the URL; the handler streams the file bytes back.

func RegisterRoutes

func RegisterRoutes(mux *http.ServeMux, d *sql.DB, r *api.Resource, customMethods map[string]CustomMethodHandler, enums FieldEnums, files FileFieldConfig, scope UserScopeConfig)

func RegisterSingletonRoutes

func RegisterSingletonRoutes(mux *http.ServeMux, d *sql.DB, r *api.Resource, singletonPath string, enums FieldEnums, scope UserScopeConfig)

RegisterSingletonRoutes registers GET and PATCH routes for a singleton resource. Singleton resources have a fixed path like /parents/{parent_id}/singular with no collection endpoints and no resource ID in the path.

func Update

func Update(d *sql.DB, plural string, path string, fields map[string]any, updateTime string, schema *openapi.Schema) error

Types

type CustomMethodHandler

type CustomMethodHandler struct {
	Method  string // "POST" or "GET"
	Handler http.HandlerFunc
}

CustomMethodHandler holds the handler and HTTP method for a custom method.

type FieldEnums

type FieldEnums = map[string][]string

FieldEnums maps a field name to the set of allowed string values for that field. A nil or empty map means no enum constraints are applied.

type FileFieldConfig

type FileFieldConfig struct {
	// Fields is the set of property names that are file fields.
	Fields map[string]bool
	// FilesDir is the on-disk root where file contents are stored.
	FilesDir string
	// ServerURL is the fully-qualified server base URL used to build
	// download URLs in resource responses.
	ServerURL string
}

FileFieldConfig carries per-resource file-field configuration through route registration. Fields is nil/empty when the resource has no file fields, in which case file-field behavior is skipped entirely.

func (FileFieldConfig) HasFileFields

func (c FileFieldConfig) HasFileFields() bool

HasFileFields reports whether the config has any file fields declared.

type StoredResource

type StoredResource struct {
	ID         string
	Path       string
	CreateTime string
	UpdateTime string
	Fields     map[string]any
}

func Get

func Get(d *sql.DB, plural string, path string, schema *openapi.Schema) (*StoredResource, error)

func List

func List(d *sql.DB, plural string, parentIDs map[string]string, schema *openapi.Schema, pageSize int, pageToken string, skip int, filter string) ([]StoredResource, string, error)

type UserScopeConfig

type UserScopeConfig struct {
	Enabled bool
}

UserScopeConfig controls user-based access scoping for resources that are children of the user resource. When Enabled is true, non-superuser requests are restricted to resources belonging to the authenticated user.

Jump to

Keyboard shortcuts

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