function
NewAdminLoader
Define a Go read function whose result is supplied to an admin component.
Example
type CountInput struct{}
type CountData struct {
Total int `json:"total"`
}
var PostCount = ridu.NewAdminLoader("post-count",
func(ctx ridu.AdminLoadContext, _ CountInput) (CountData, error) {
posts, err := ctx.List("posts", ridu.ListOptions{Limit: 1})
return CountData{Total: posts.Total}, err
},
)Arguments
| Argument | Type | Description |
|---|---|---|
key | string | Application-wide unique key, at most 80 characters. Start with a lowercase letter; use lowercase letters, digits, and single hyphens between words, such as editorial-post-summary. Use the same key from generated adminLoaders. |
handler | func(AdminLoadContext, | Read function receiving the current request context and URL query inputs. Return browser-safe data or an error. |
Returns
A loader definition to append to Config.Admin.Loaders. Defining or registering it does not run the data read.
AdminLoaderDefinitionHow it works
Register the result in Config.Admin.Loaders, then run ridu generate. Generation derives the input and output TypeScript types from your Go structs.
Use explicit json tags. Query inputs are scalar fields; missing values retain Go zero values. Return structs, scalar values, arrays, slices, pointers, or time.Time; maps, recursive types, and custom JSON codecs are not supported.
The function can run on page entry, URL changes, or refresh. Keep it read-only. ctx.List, ctx.Find, and ctx.Global enforce Ridu permissions and the current locale; external services need your own access checks.
Full signature
func NewAdminLoader[Input, Output any](
key string,
handler func(AdminLoadContext, Input) (Output, error),
) AdminLoaderDefinitionRelated types
AdminLoadContextRead content for the signed-in user while a Go admin loader runs.
AdminLoaderDefinitionA Go admin loader ready to register in your application's Admin.Loaders.