Help us shape the future of Go! Take the 2026 Go Developer Survey

example

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package example provides a minimal example of implementing the AppBackend interface. This demonstrates how to create an app that can run in both multi-app and single-app modes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExampleApp

type ExampleApp struct {
	// contains filtered or unexported fields
}

ExampleApp is a minimal implementation of the AppBackend interface. It demonstrates the core patterns for building multi-app compatible backends.

func NewExampleApp

func NewExampleApp() *ExampleApp

NewExampleApp creates a new example app.

func (*ExampleApp) EntSchemas

func (a *ExampleApp) EntSchemas() []ent.Schema

EntSchemas returns Ent schemas for this app. This example uses raw SQL migrations instead of Ent schemas.

func (*ExampleApp) Migrations

func (a *ExampleApp) Migrations() []multiapp.Migration

Migrations returns database migrations for this app. Each migration runs in the app's schema (e.g., app_example).

func (*ExampleApp) Name

func (a *ExampleApp) Name() string

Name returns the app's display name.

func (*ExampleApp) OnRegister

func (a *ExampleApp) OnRegister(ctx context.Context, cfg *multiapp.AppConfig) error

OnRegister is called when the app is registered with the server. Use this for one-time initialization that requires the app config.

func (*ExampleApp) OnShutdown

func (a *ExampleApp) OnShutdown(ctx context.Context) error

OnShutdown is called during graceful shutdown. Use this to clean up resources.

func (*ExampleApp) Routes

func (a *ExampleApp) Routes(deps multiapp.Dependencies) chi.Router

Routes returns the app's HTTP routes. These routes will be mounted at / in single-app mode, or dispatched via X-App-ID in multi-app mode.

func (*ExampleApp) Slug

func (a *ExampleApp) Slug() string

Slug returns the app's unique identifier.

type Item

type Item struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	CreatedAt   string `json:"created_at"`
	UpdatedAt   string `json:"updated_at"`
}

Item represents a sample data model.

Directories

Path Synopsis
Package main demonstrates running apps in single-app and multi-app modes.
Package main demonstrates running apps in single-app and multi-app modes.

Jump to

Keyboard shortcuts

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