Documentation
¶
Index ¶
- func Delete(d *sql.DB, plural string, path string) (bool, error)
- func Insert(d *sql.DB, plural string, r *StoredResource, parentIDs map[string]string, ...) error
- func MakeDownloadHandler(d *sql.DB, r *api.Resource, fileFields map[string]bool, filesDir string) http.HandlerFunc
- func RegisterRoutes(mux *http.ServeMux, d *sql.DB, r *api.Resource, ...)
- func RegisterSingletonRoutes(mux *http.ServeMux, d *sql.DB, r *api.Resource, singletonPath string, ...)
- func Update(d *sql.DB, plural string, path string, fields map[string]any, ...) error
- type CustomMethodHandler
- type FieldEnums
- type FileFieldConfig
- type StoredResource
- type UserScopeConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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.
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 ¶
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
}
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.