Skip to content

Building your first Iridium application (manually)

1. Create a new Iridium package

Create a new go package in your application to store your iridium files

sh
mkdir iridium

Create your first panel

See more on panels here

sh
# in root directory.
# Create a new panel directory & admin_panel go file
mkdir iridium/panels
touch iridium/panels/admin_panel.go

Create a basic adminstrator panel

go
// admin_panel.go

func NewAdminPanel(mux *http.ServeMux) *panel.Panel {
	return panel.NewPanel(mux).
		ID("admin").
		Path("admin").
		Resources(
            /* Will register your first resource here */
        ).
		Middleware(
			middleware.SetPanel,
			middleware.Spa,
			middleware.ErrorPages,
		)
}

2. Create a resource

Create a resources directory

sh
# in root directory.
mkdir iridium/resources/

Then create a new user resource file.

sh
touch iridium/resources/user_resource.go
go
// iridium/resources/user_resource.go
package resources

import (
    "github.com/iridiumgo/iridium/core/resource"
    "github.com/iridiumgo/iridium/view/icon/icons"
    // Import your models
)

func NewUserResource() resource.Resource {
    // Assuming gorm driver
    return resource.NewResource("Users").
        Icon(icons.Users).
        // Your pages, tables, forms, etc...
        Pages(
            resource.NewListPage(),
            resource.NewCreatePage(),
            resource.NewEditPage(),
        )
}

3. Register your resource

Go back to your admin_panel.go and register your new resource.

go
// iridium/panels/admin_panel.go
// ...
        Resources(
            resources.NewUserResource(), // Register here <---
        ).
// ...

4. Wire everything up

Finally, in your main.go, instantiate the panel and attach it to your router.

go
// main.go
package main

import (
    "net/http"
    "my-app/iridium/panels"
)

func main() {
    mux := http.NewServeMux()

    // Initialize your DB connection here...
    
    // Register the panel
    panels.NewAdminPanel(mux)

    http.ListenAndServe(":8080", mux)
}

Now run your app!

sh
go run main.go

Visit http://localhost:8080/admin to see your new Iridium panel.

Released under the MIT License.