web

command module
v0.0.0-...-ee23756 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 50 Imported by: 0

README

go-users Web Example

This example demonstrates the go-users package with a complete web interface showcasing all features:

Features Showcased

1. User Inventory (/users)
  • Paginated list of users with lifecycle states
  • View user details
  • Apply lifecycle transitions (pending → active → inactive → suspended)
2. Activity Feed (/activity)
  • Real-time monitoring of user actions
  • View activity logs with verb, object type, and metadata
  • Pagination and filtering
  • Snapshot widget built from ActivityStats for fast at-a-glance totals
  • JSON endpoint at /activity/stats for front-end dashboards
3. User Invitations (/invites)
  • Send email invites to new users
  • Track invitation status
  • Token-based invite acceptance
4. User Profiles (/profile)
  • View and edit user profile information
  • Display name, avatar URL, bio
  • Locale and timezone settings
5. User Preferences (/preferences)
  • Manage user preferences with scope hierarchy
  • Support for user/org/tenant scopes
  • Key-value storage with JSON values
6. Role Management (/roles)
  • List custom roles
  • Assign/unassign roles to users
  • View role details and assignments
7. Schema & Scope Utilities
  • Multi-tenant scope guard backed by a workspace directory (tenant + workspace labels)
  • /admin/schema-demo shows the registry payload the go-admin/go-cms consumers poll
  • Demo users are pinned to unique tenants/workspaces so guard enforcement is easy to observe

Demo Accounts

Two actors are pre-seeded so you can sign in immediately:

Email Password Tenant / Workspace
maya.ops@example.com ChangeM3! Ops Tenant / Ops Workspace
leon.commerce@example.com ChangeM3! Commerce Tenant / Commerce Workspace

Each sign-in will see only the users, activity, and roles within their assigned scope because every command/query passes through the shared guard.

REST API Endpoints

All features are also exposed via RESTful API with full CRUD operations:

  • GET /api/user-activities - List activity logs (read-only)
  • GET /api/user-profiles - List/filter profiles
  • POST /api/user-profile - Create profile
  • PUT /api/user-profile/:id - Update profile
  • GET /api/user-preferences - List/filter preferences
  • POST /api/user-preference - Create preference
  • PUT /api/user-preference/:id - Update preference
  • DELETE /api/user-preference/:id - Delete preference
  • GET /api/user-roles - List roles
  • POST /api/user-role - Create role
  • GET /api/user-role-assignments - List role assignments
  • GET /activity/stats - Aggregated counts used by the dashboard widget

Architecture

Two-Track Routing
  1. API Routes (/api/*) - Auto-generated by go-crud controllers

    • JSON responses
    • RESTful conventions
    • OpenAPI documentation
  2. Web Routes (/users, /profile, etc.) - Custom HTML handlers

    • Server-side rendered templates
    • Flash messages for feedback
    • CSRF protection
    • Guard-aware helpers that hydrate the templates with scope + activity data
Service Layer Integration

Web handlers use the go-users Service commands/queries directly:

  • service.Commands().UserInvite.Execute()
  • service.Queries().UserInventory.Query()
  • etc.

This demonstrates how to build admin panels or dashboards on top of the go-users package.

Running the Example

# From the repository root
/Users/goliatone/.g/go/bin/go run ./examples/web

The server will start on http://localhost:8978

Configuration

The example uses environment variables and defaults:

SERVER_PORT=8978
SERVER_HOST=localhost

View full configuration in config/config.go.

Technology Stack

  • go-users - User management service layer
  • go-crud - Auto-generated REST API
  • go-router - HTTP routing with go-router/fiber adapter
  • go-auth - Authentication and session management
  • Bun - SQL query builder and ORM
  • SQLite - Embedded database (in-memory)
  • Django Templates - Server-side rendering

Project Structure

examples/web/
├── main.go              # App bootstrap
├── api_routes.go        # go-crud controller setup
├── web_routes.go        # Custom HTML handlers
├── config/
│   └── config.go        # Configuration struct
├── views/
│   ├── layout.html      # Base template
│   ├── index.html       # Home page
│   ├── users/           # User inventory views
│   ├── activity/        # Activity feed views
│   ├── invites/         # Invite views
│   ├── preferences/     # Preferences views
│   ├── profile/         # Profile views
│   ├── roles/           # Role management views
│   └── errors/          # Error pages
└── public/
    ├── css/
    │   └── main.css     # Styles
    └── js/
        └── app.js       # Client-side JS

Next Steps

  • Add bulk user operations
  • Enhance activity filtering
  • Add real-time updates with WebSockets

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL