Skip to content

Panels

Panels are the staging ground for related resources & pages under a shared route.

They are the top level structure of your application, & allow you customize route information, middleware, authentication, themes, styles, etc. that are inherited by the rest of your app's pages.

You can have multiple panels per application with different configurations, allowing you to for example, have a designated area for administrator access, and user access.

Defining a panel

It recommended to define your panels in a new go file.

Panels need to be registered in your applications initalization logic using the panel registry and passed a mux during creation. See initilization for instructions.

Basic Admin Panel Example

go
// admin_panel.go

func NewAdminPanel(mux *http.ServerMux) *panel.Panel {
    return panel.NewPanel(mux).
        ID("admin").
        Path("admin").
        Resources(
            resources.NewUserResource()
        ).
        Pages(
            pages.NewGeneralPage()
        ).
        Middleware(
            middleware.SetPanel,
            middleware.Spa,
            middleware.ErrorPages,
        )
}

We'll break down each of these functions (and more) below.

Panel Configuration

ID

Your panel requires a unique identifier for it's own name. If a name is not set, your app will default to the admin name and route.

Route

Your panel requires a unique base route to prefix all subsequent routes that will be registered beneath it. This defaults to /admin behind the scenes if no route is provided.

Both /admin and admin are accepted as route prefixes as a leading slash is included if none is provided.

Resources

See how to create resources here

If you've created a resource to manage a particular set of data, you'll need to register that with your panel under the Resources method.

The same resource can be registered across multiple panels. Each time it is registered, your resource routes are registered for that panel. Mean a resource registered for an admin & app panel, will have two sets of routes registered.

go
// example of registering a User resource
Resources(
    resources.NewUserResource()
).

Pages

See how to create pages here

If you've created a page you'd like to include under a panel, you'll need to register them in the Pages method.

go
Pages(
    pages.NewGeneralPage()
)

Middleware

Middleware wraps all requests that occur under this particular panel's route. This means that routes generated from your resources & pages and registered to the current panel, will flow through your middleware in the order you define them.

Iridium has some middleware of it's own that should be included on each new panel. Those are listed below:

go
// Please include the listed middleware.
// Your custom middleware should be included here as well.
Middleware(
    // Sets the current panel id as part of your request context.
    middleware.SetPanel, // <- Required
    // Performs proper wrapping of templ components for refreshes & other navigation/requests.
    middleware.Spa, // <- Required
    // Renders error pages. 
    middleware.ErrorPages, // <- optional.

    //Your custom middleware here    
)

The Middleware function expects your middleware to conform to the following pattern:

go
import "net/http"
func(next http.Handler) http.Handler

Theme route

For more on themeing, see here

Iridium supports shadcn & custom themes. You can set the theme path with the ThemePath method.

go
ThemePath("./static/assets/custom_theme.css")

You'll also need to properly serve that custom_theme.css file (and embed it if required) for Iridium to read it for your panel. Please see our networking section.

Iridium supports three nav bar positions: Left, Right, & Top

You can set the navigation's positions using the NavStyle method

go
import "github.com/asosick/iridium/core/panel"

// also supports panel.NavTop, panel.NavRight
NavStyle(panel.NavLeft)

Released under the MIT License.