Skip to content

Resources

Resources group together related pages that generally interact with a single source of data, like a database data.

A typical resource will have List, View, Edit, & Create pages that provide users a location to perform traditional

operations.

Pages

Resources themselves have no renderable content, they simple contain links to related pages. These pages can contain tables, forms, widgets, and custom components. You are also able to define any number of pages under your resource, and are not require to have the traditional CRUD pages.

Building a Resource

To build a resource:

  1. Create a new directory/package to house your resource's files
  2. Create a new resource.go file inside your new package

Type Generation

To generate type aliases for your resource, please include & run the following at the top of your new resource file.

go
//go:generate go run github.com/iridiumgo/iridium/cmd/alias -group=resource -type=User -source=./iridium/models/user.go -driver=gorm

Example

The following basic resource is being created for a Users struct that interfaces with a GORM model.

go
// user_resource.go

func NewUserResource() UserResource {
	r := Resource("Users").
		Driver(gormDriver).
		Icon(icons.Users).
		Table(*UserResourceTable()).
		Form(*UserResourceForm()).
	r.Pages(
		r.NewListPage(),
		r.NewViewPage(),
		r.NewCreatePage(),
		r.NewEditPage(),
	)
	return r
}

Data Source

By default, your resources assume your provided model type is a GORM model. If instead your model is contained in a plain array or api, you'll need to define a new driver

Released under the MIT License.